【发布时间】:2018-07-18 14:37:15
【问题描述】:
我已经编写了代码,其中有一个包含所有类型食物的数据框。然后,我使用 str.contains 将其拆分为水果和蔬菜系列。我编写了代码,将两个系列中常见的任何食物附加到列表中:
fruit = fruit_2.tolist()#converting the series to a list
veg = veg_2.tolist()#converting the series to a list
for x in range (len(fruit)):
for y in range (len(veg)):
if fruit[x] == veg[y]:
both.append(fruit[x])
print(both)
这只是想知道是否有人有一个使用 pandas 并且不使用 for 循环的解决方案。 谢谢
【问题讨论】:
-
只要够了