[英]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.我面临一个奇怪的问题,我试图用取自另一个具有相关值的值(相同长度)的值替换 dataframe 中的所有 NaN 值。
Here's a glimpse for the "target dataframe" in which I want to replace the values: data_with_null
这是我要替换值的“目标数据框”的一瞥:
data_with_null
Here's the dataframe where I want to take data from: predicted_paticipant_groups
这是我想从中获取数据的 dataframe:
predicted_paticipant_groups
ticipant_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)但它只是用第一个值填充所有值 NaN 值(Infra)
Is it because of the indexes of data_with_null
are all zeros?是因为
data_with_null
的索引都是零吗?
Reset the index and try again.重置索引并重试。
data_with_null.reset_index(drop=True, inplace=True)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.