简体   繁体   English

比较两个不同数据帧的“名称”列

[英]Compare 'name' columns of two different dataframes

actual_df['new_col'] = np.where(lookup_df['name'].str.contains(actual_df['name'] + '-'), lookup_df['name'], 'Not Found')

The above code throws the following error:上面的代码抛出以下错误:

'Series' objects are mutable, thus they cannot be hashed “系列”对象是可变的,因此它们不能被散列

How to do the required lookup with another data frame?如何使用另一个数据框进行所需的查找?

Instead of "str.contains()" method, use slicing, if length of both columns are same.如果两列的长度相同,请使用切片而不是“str.contains()”方法。

actual_df['new_col']= np.where(lookup_df['name'] == actual_df["name"].str[:-1], df2['name2'], 'Not Found')

and if not, use "df.isin()" method of pandas :如果没有,请使用熊猫的“df.isin()”方法:

actual_df['new_col'] = actual_df["name"][actual_df["name"].isin(lookup_df["name"].str[:-1])]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM