如何基于另一列中的值打印/返回值?
df = my_df[['Index','FRUITS']]
print(df)
Index FRUITS
7 Green Apple
7 Mango
7 Orange
7 Strawberry
9 Pineapple
9 Banana
9 Grapes
10 Orange (Unripe)
10 Plum
L = ['apple','orange']
在这里,我要检查字符串是否是 Apple 或 橙色 每个索引 的子字符串中出现的存在,无论大小写如何,返回 > 这两个水果之一未找到!
我尝试使用来自不同答案的方法,并尝试了groupby并遍历水果:
out = df.groupby('Index')['FRUITS'].apply(lambda x: L in x)
TypeError: 'in <string>' requires string as left operand,not list
因此,预期输出为:
[9,10]