r/pythonhelp • • Dec 23 '21

Updating a Dataframe from another Dataframe

Hi All,

I hope you are well

I was wondering if I could get some help!

I have 2 dataframes, e.g.:

Unique ID Email Number

0 123 No No

1 456 No No

2 789 No No

2)

Unique ID Email2 Number2

0 123 Yes Yes

1 456 Yes Yes

2 789 Yes No

How can I update the 1st dataframe so it has the values of the second data frame based on Unique ID, therefore the 1st dataframe becomes:

Unique ID Email Number

0 123 Yes Yes

1 456 Yes Yes

2 789 Yes No

Apologies if this does not make sense!

2 Upvotes

2 comments sorted by

1

u/CraigAT Dec 23 '21

Someone may have a better answer but you could use "concat" or "merge" to combine the dataframes, "drop" the Email and Number columns, then "rename" Email2 and Number2 columns (dropping the 2).

https://pandas.pydata.org/Pandas_Cheat_Sheet.pdf

1

u/CraigAT Dec 23 '21

Or just rename the columns in dataframe 2 and use that.