慕尼黑8549860
您还可以应用 lambda,这样: df['new_column'] = df.apply(lambda x: 1 if 'DIGITAL_SOURCE' in x['file_name'] else 0, axis=1 )例子:df = pd.DataFrame({"LOCATION":["USA","USA","USA","USA","JAPAN","JAPAN"],"file_name":["DIGITAL","DIGITAL","DIGITAL","DIGITAL","DIGITAL_SOURCE","DIGITAL_SOURCE"]}) LOCATION file_name0 USA DIGITAL1 USA DIGITAL2 USA DIGITAL3 USA DIGITAL4 JAPAN DIGITAL_SOURCE5 JAPAN DIGITAL_SOURCEdf['new_cl'] = df.apply(lambda x: 1 if 'DIGITAL_SOURCE' in x['file_name'] else 0, axis=1 ) LOCATION file_name new_cl0 USA DIGITAL 01 USA DIGITAL 02 USA DIGITAL 03 USA DIGITAL 04 JAPAN DIGITAL_SOURCE 15 JAPAN DIGITAL_SOURCE 1