df1 before update:
A B C
0 1 4 7
1 2 5 8
2 3 6 9
df2:
B
0 10
1 11
2 12
df1 after update:
A B C
0 1 10 7
1 2 11 8
2 3 12 9
Please note that if any of the values of column B of df2 is nan, then that corresponding value in df1 will not get updated.
import numpy
import pandas
df1 = pandas.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': [7, 8, 9]})
print("df1 before update: \n", df1)
df3 = pandas.DataFrame({'B': [13, numpy.nan, 15]})
df1.update(df3)
print("df1 after update: \n", df1)
The above program will print the following output:
df1 before update:
A B C
0 1 4 7
1 2 5 8
2 3 6 9
df1 after update:
A B C
0 1 13.0 7
1 2 5.0 8
2 3 15.0 9








































0 Comments