Search code examples
pythondataframescikit-learnsklearn-pandas

fillna() only fills the 1st value of the dataframe


I'm facing a strange issue in which I'm trying to replace all NaN values in a dataframe with values taken from another one (same length) that has the relevant values.

Here's a glimpse for the "target dataframe" in which I want to replace the values: data_with_null

![enter image description here

Here's the dataframe where I want to take data from: predicted_paticipant_groups

enter image description here

I've tried:

data_with_null.participant_groups.fillna(predicted_paticipant_groups.participant_groups, inplace=True)

but it just fills all values NaN values with the 1st one (Infra)

enter image description here

Is it because of the indexes of data_with_null are all zeros?


Solution

  • Reset the index and try again.

    data_with_null.reset_index(drop=True, inplace=True)