我有一个数据帧,里面有nan:

>>>df.head()
Out[1]:
            JPM US SMALLER COMPANIES C ACC
1990-01-02                             NaN
1990-01-03                             NaN
1990-01-04                             NaN
1990-01-05                             NaN
1990-01-08                             NaN

我有另一个数据帧,其中包含值:
>>>t.head()
Out[1]:
1990-01-02    51.95
1990-01-03    52.63
1990-01-04    53.04
1990-01-05    52.07
1990-01-08    51.73
Name: JPM US SMALLER COMPANIES C ACC, dtype: float64

不幸的是,df.fillna似乎不适合我:
>>>df.fillna( t ).head()
Out[1]:
            JPM US SMALLER COMPANIES C ACC
1990-01-02                             NaN
1990-01-03                             NaN
1990-01-04                             NaN
1990-01-05                             NaN
1990-01-08                             NaN

[5 rows x 1 columns]

为什么会这样?我在熊猫队0.13.1

最佳答案

你需要inplace

df[1].fillna(0, inplace=True)

关于python - Pandas fillna不工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25147707/

10-15 14:06