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