简体   繁体   English

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

[英]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.

相关问题 如何迭代数据框名称列表以获取列表中每个数据框第一行的第一个值 - How to iterate of a list of dataframe's name to get the 1st value of 1st row of every dataframe in the list 如何在python数据框中的列中获取值的第一次出现 - How to get the 1st occurence of a value in a column in python dataframe 使用map(dict)的fillna()不仅可以填充NaN,还可以填充所有值 - fillna() with map(dict) fills not only NaNs, but all values 在具有应用值的 dataframe 中使用 fillna - Using fillna in a dataframe with applied value Pandas dataframe由一些值组成 - Pandas dataframe fillna by some value 如何合并 2 dataframe,创建只出现在第二个 dataframe 但不出现在第一个的行和 groupby 求和? - How to combine 2 dataframe, create a row that appear only in the second dataframe but not in the 1st and groupby to get the sum? 如何仅用逗号前第一个出现的单词替换 dataframe 文本列 - How to replace dataframe text column with only the 1st occuring word / words before a comma Python Dataframe: To get a column value from 2nd dataframe based on a column in the 1st dataframe is in between two columns in the 2nd dataframe - Python Dataframe: To get a column value from 2nd dataframe based on a column in the 1st dataframe is in between two columns in the 2nd dataframe Pandas替换DataFrame中的第一个结果 - Pandas Replace 1st Result in a DataFrame 如何过滤我的数据框以仅显示每个月的第一个工作日? - How can I filter my dataframe to only show the 1st business day of each month?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM