GodProbablyExists
GodProbablyExists

Reputation: 83

Update pandas dataframe column with another column in another dataframe on index overlap

I wish to update column A in dfA with column B in dfB on index overlap

dfA

     A
1    1
2    1
3    1
4    1

dfB

     B
3    2
4    2
5    2
6    2

Desired result:

     A
1    1
2    1
3    2
4    2

What is the simplest way to do this?

Upvotes: 0

Views: 58

Answers (1)

BENY
BENY

Reputation: 323226

Try with update

dfA.update(dfB.rename(columns = {'B':'A'}))

Upvotes: 2

Related Questions