簡體   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')

上面的代碼拋出以下錯誤:

“系列”對象是可變的,因此它們不能被散列

如何使用另一個數據框進行所需的查找?

如果兩列的長度相同,請使用切片而不是“str.contains()”方法。

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

如果沒有,請使用熊貓的“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