无法使用 fillna 函数替换 nan 值

问题描述 投票:0回答:1

我有一个 pandas 数据框。我正在尝试使用 fillna 函数的 ffill 方法将其中一列的 nan 值替换为最后一个有效观察值。但这似乎不起作用。

我已经验证列的 nan 值实际上是 nan 值而不是字符串

This image is a small snapshot of the dataframe. The last column is whose nan values I want to replace This snapshot is of the console showing that the column nan values are actually nan values and not strings

我不知道我做错了什么。请帮忙!

python pandas dataframe nan fillna
1个回答
0
投票

您可以尝试以下方法:

df['1900CE_IV'] = df['1900CE_IV'].fillna(method = 'ffill')
© www.soinside.com 2019 - 2024. All rights reserved.