Skip to content
Advertisement

How to merge two dataframe in pandas to replace nan

I want to do this in pandas:

I have 2 dataframes, A and B, I want to replace only NaN of A with B values.

JavaScript

Advertisement

Answer

The official way promoted exactly to do this is A.combine_first(B). Further information are in the official documentation.

However, it gets outperformed massively with large databases from A.fillna(B) (performed tests with 25000 elements):

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement