Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
685 views
in Technique[技术] by (71.8m points)

python - pandas fillna not working

I have a dataframe with nans in it:

>>>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

I have another dataframe with values in it:

>>>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

Unfortunately, df.fillna does not appear to be working for me:

>>>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]

Why is this happening? I am on pandas 0.13.1

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need inplace

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...