python - 尝试用特定值填充 NaN 值

标签 python pandas dataframe

这个

df.loc[df['Feature reference #'] == feature][development_column] = df.loc[df['Feature reference #'] == feature][development_column].fillna(req_dict[feature])

是我试图修复的代码行。基本上,当我打印时

df.loc[df['Feature reference #'] == feature][development_column].fillna(req_dict[feature])

它显示了替换了 NaN 值的更新系列。但我希望这个更新后的系列保存在原始 DF 中。

也尝试过inplace=True,但也不成功。

我基本上希望上面的代码行按逻辑工作。

最佳答案

您可以使用:

df.loc[df['Feature reference #'] == feature, development_column] = df.loc[df['Feature reference #'] == feature, development_column].fillna(req_dict[feature])

df.loc[df['Feature reference #'] == feature, development_column].fillna(req_dict[feature], inplace=True)

关于python - 尝试用特定值填充 NaN 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76201070/

相关文章:

python - 从 Atom 运行 Python

python - 获取目录的绝对路径

python-3.x - 根据特定条件生成带有填充的行 - pandas

python - Pandas - 将数据帧多索引转换为日期时间对象

python - 使用 uuid.uuid4() 创建新文件

python - 如何使热图中的单元格保持正方形?

python - 计算一列中子字符串在另一列中的出现次数

python - 使用 Pandas 合并两个 csv 文件

python - FutureWarning : In a future version of pandas all arguments of DataFrame. any 和 Series.any 将仅包含关键字

python - 如何一次转换多个 Spark 数据框列类型?