我有一个数据框架,其中包含来自城市的不同子市场的列。我需要遍历该列,并检查该行中的值是否与列表中可能存在的任何项匹配。然后将该列表作为列添加到原始数据框
submarket_list = [ 'South Financial District', 'Financial District', South of Market]
submarket_check = []
for index,row in test_df.iterrows():
for j in submarket_list:
if row['Submarket'] == j:
submarket_check.append("yes")
else:
submarket_check.append("No")
test_df['Submarket Check'] = submarket_check
test_df
test_df["Submarket"].isin(submarket_list)
将给你一列布尔值。这是你所需要的一切