繁体   English   中英

fillna() 仅填充 dataframe 的第一个值

[英]fillna() only fills the 1st value of the dataframe

我面临一个奇怪的问题,我试图用取自另一个具有相关值的值(相同长度)的值替换 dataframe 中的所有 NaN 值。

这是我要替换值的“目标数据框”的一瞥: data_with_null

![在此处输入图像描述

这是我想从中获取数据的 dataframe: predicted_paticipant_groups ticipant_groups

在此处输入图像描述

我试过了:

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

但它只是用第一个值填充所有值 NaN 值(Infra)

在此处输入图像描述

是因为data_with_null的索引都是零吗?

重置索引并重试。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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