嗨,我有两个数据帧
DF1
Name | Class
pechi | Mr pechi lives in India
Kumar | Mr kumar lives in US
DF2,
Name |
Kumar
如果DF2中的字符串与DF1中的任何字符串匹配[“Class”]
那么DF1中的整行应该附加到我的DF3中
My desired DF3 Should be,
DF3,
Name | Class
Kumar | Mr kumar lives in US
有人帮我解决这个问题。你知道吗
我试过这个方法
if df1[['Class']].str.contains(item1):
but I am getting ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
使用
isin
和布尔索引:输出:
相关问题 更多 >
编程相关推荐