python中如何在两个数据帧之间查找关键字find

2024-05-15 21:21:48 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我有两个数据帧

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().

Tags: 数据字符串nameinclassusdf1mr