简体   繁体   English

如何为fillna更改pandas中的确切行/列数据点

[英]how to change exact row/column data point in pandas for fillna

I want to fill nan values using some linear regression model.我想使用一些线性回归 model 填充 nan 值。 I use other columns that are not nan and I compute the one that is NaN.我使用其他不是 nan 的列,我计算的是 NaN 列。

Now, I have a problem to change the following value.现在,我在更改以下值时遇到了问题。

I have an array nan_values_predicted and the indexes of these values in the main dataset.我有一个数组nan_values_predicted和主数据集中这些值的索引。

But I can't find a way to change the exact data point.但我找不到改变确切数据点的方法。

I tried something like:我试过类似的东西:

df.loc[index_1]['feature_1'] = df.loc[index_1]['feature_1'].fillna(predicted_feature_1)

and many other variations, a bit smarter than this one but they don't work.和许多其他变体,比这个更聪明,但它们不起作用。 Any help?有什么帮助吗?

I was missing this...我错过了这个...

as opposed to doing df.loc[index_1]['feature_1'] = some_value I should've done df.loc[index_1, 'feature_1'] = some_value而不是做df.loc[index_1]['feature_1'] = some_value我应该做df.loc[index_1, 'feature_1'] = some_value

And everything works now现在一切正常

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

相关问题 熊猫如何在列上填充文本? - Pandas how to fillna in place on a column? 如何根据pandas中的日期填写数据 - How to fillna the data according to the date in pandas python - Pandas - FillNa 与另一个具有相似列的非空行 - python - Pandas - FillNa with another non null row having similar column 熊猫 | 特定索引之间的填充(随行变化) - Pandas | Fillna between specific indexes (which change with row) 如何使用 pandas fillna NaN 与下一行值的负数 - how to use pandas fillna NaN with the negative of the next row value 如何使用零值进行填充,直到数据出现在每列中,然后对 pandas 数据帧中的每一列使用前向填充 - How to do a fillna with zero values until data appears in each column, then use the forward fill for each column in pandas data frame 如何使用fillna返回pandas DataFrame中相应列的平均值 - How to return the mean value of the corresponding column in a pandas DataFrame using fillna 如何正确使用fillna()作为熊猫数据框中的日期时间列(不起作用)? - How to correctly use fillna() for a datetime column in pandas dataframe (not working)? 如何将 numpy fillna() 和 numpy.where() 用于 Pandas DataFrame 中的列? - How to use numpy fillna() with numpy.where() for a column in a pandas DataFrame? 如何将另一整列作为参数传递给 pandas fillna() - How to pass another entire column as argument to pandas fillna()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM