TransWikia.com

Comparing 2 columns from separate dataframes and copy some row values from one df to another if column value matches in pandas

Data Science Asked by Asif17 on April 28, 2021

Im relatively new to pandas andpython . I have a simple problem but I can not find the solution . I have 2 dataframes DF1 and DF2 as shown in image

Both dataframes have ID coluumns. I wannt to check if the ID for a row in DF1 matches any of ID in DF2, then I want to copy the diameter value from DF2 and paste it to DF1 in a new column. Eventually what I want to achieve at the end is DF3 shown in image below.

Help will be highly appreciated.

Dataframes DF1, DF2 and DF3

One Answer

You may merge two dfs:

df1.merge(df2, on=['id'], how='left')

Answered by imitusov on April 28, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP