如果字符串在" Language_cat"列表匹配"语言"中的任何行。 df_dat dataframe中的列然后为对应于同一行的该值生成虚拟对象:
Language_cat = ['english','french','deutsch','italian','russian','spanish']
for j in Language_cat:
df_dat[j+'lang_cat'] = df_dat['Languages'].apply(lambda x: 1 if df_dat.Languages.str.contains(j) else 0)
然而,这是错误
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
答案 0 :(得分:0)
Language_cat = ['english','french','deutsch','italian','russian','spanish']
for j in Language_cat:
df_dat[j+'lang_cat'] = df_dat['Languages'].str.contains(j).astype(int)