Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+12 votes

Let's say I have a data frame df as following:

(Index) Name  Height
0         A     56
1         B     70
2         C       

And a column col as following:

(Index) Height
0
1         69
2         50

What will be the result of df['Height'].combine_first(col) ? There is an overlap at the row with index 1.

asked in DATA360_Spring2019 by (1 point)

1 Answer

+7 votes
 
Best answer

It's called "combine_first" because if there are multiple values, it will choose the first one!

Another way of thinking about it is that only null (NaN) values in the first series will be replaced by values from the second series. Non-null values won't be affected. This is basically the way the official docs describe it: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.combine_first.html

answered by (3.4k points)
selected by
...