简体   繁体   中英

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

![在此处输入图像描述

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

在此处输入图像描述

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)

在此处输入图像描述

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

Reset the index and try again.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM