Skip to content
Advertisement

pandas concat generates nan values

I am curious why a simple concatenation of two dataframes in pandas:

JavaScript

of the same shape and both without NaN values

JavaScript

can result in a lot of NaN values if joined.

How can I fix this problem and prevent NaN values being introduced? Trying to reproduce it like

JavaScript

failed e.g. worked just fine as no NaN values were introduced.

Advertisement

Answer

I think there is problem with different index values, so where concat cannot align get NaN:

JavaScript

Solution is reset_index if indexes values are not necessary:

JavaScript

EDIT: If need same index like aaa and length of DataFrames is same use:

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