dai*_*yue 3 python dataframe python-3.x pandas
我有以下内容df,
A
1.0
2.0
3.0
NaN
Run Code Online (Sandbox Code Playgroud)
我试图用 stringfillna替换。NaNnot existed
df.fillna(value={'A': 'not existed'}, axis=1, inplace=True)
Run Code Online (Sandbox Code Playgroud)
但我收到以下错误,
NotImplementedError: Currently only can fill with dict/Series column by column
Run Code Online (Sandbox Code Playgroud)
如果我使用replace,它会起作用,
df['A'].replace(np.nan, 'not existed')
Run Code Online (Sandbox Code Playgroud)
我想知道为什么会这样。
对我来说,删除工作axis=1:
print (df)
A B
0 NaN NaN
1 2.0 7.0
2 3.0 8.0
3 NaN 7.0
df.fillna({'A': 'not existed'}, inplace=True)
print (df)
A B
0 not existed NaN
1 2 7.0
2 3 8.0
3 not existed 7.0
Run Code Online (Sandbox Code Playgroud)
df.fillna({'A': 'not existed', 'B':'nwwww'}, inplace=True)
print (df)
A B
0 not existed nwwww
1 2 7
2 3 8
3 not existed 7
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4401 次 |
| 最近记录: |