07-python-pandas-missingdata
7. Pandas高级教程之:处理缺失数据
简介
NaN的例子
In [1]: df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f', 'h'],
...: columns=['one', 'two', 'three'])
...:
In [2]: df['four'] = 'bar'
In [3]: df['five'] = df['one'] > 0
In [4]: df
Out[4]:
one two three four five
a 0.469112 -0.282863 -1.509059 bar True
c -1.135632 1.212112 -0.173215 bar False
e 0.119209 -1.044236 -0.861849 bar True
f -2.104569 -0.494929 1.071804 bar False
h 0.721555 -0.706771 -1.039575 bar True整数类型的缺失值
Datetimes 类型的缺失值
None 和 np.nan 的转换
缺失值的计算
使用fillna填充NaN数据
方法名
描述
使用dropna删除包含NA的数据
插值interpolation
使用replace替换值
最后更新于
这有帮助吗?