【发布时间】:2021-03-19 20:18:11
【问题描述】:
我想检查一个数据框中的列中的值是否存在于第二个数据框的列中。如果存在,则将该值添加到第二个数据帧中同一行的新列中。所有值都是字符串值。两个数据框的大小都不同。第二个数据框也有大约 70 万条记录。所以我拥有的数据框:
DF1
THINGS
book+pen
CAR
chair
laptop
DF2
Description
I want a new book.
I will pen down this things
A quick ride in my new car.
Cars are awesome.
My laptop's memory is bad.
Maybe try sitting on that CHAIR.
我想要的输出是添加一个“更新”列:
Description Updated
I want a new book. book
I will pen down this things pen
A quick ride in my new car. car
Cars are awesome. car
My laptop's memory is bad. laptop
Maybe try sitting on that CHAIR. chair
Search for that book in my laptop. book+laptop
我已经尝试过暴力方法,但处理时间太长。提前致谢!
【问题讨论】:
-
如果你有范围索引,你可以只在索引上合并,如果没有,你可以
df.reset_index()df2.reset_index()然后只是pd.merge(df, df2, left_index=True, right_index=True)也可以了解更多关于stackoverflow.com/questions/40468069/…的信息
标签: python python-3.x pandas list dataframe