简体   繁体   中英

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?

Try with update

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM