2018-12-18
阅读量:
1014
pandas如何填充缺失值?
填充缺失值:
现在,使用数据的均值或模式替换任何NaN值fillna
,可以根据需要替换特定列甚至整个DataFrame中的所有NaN值。
import numpy as np
import pandas as pd
# Create a DataFrame
dframe = pd.DataFrame({'Geeks': [23, 24, 22],
'For': [10, 12, np.nan],
'geeks': [0, np.nan, np.nan]},
columns = ['Geeks', 'For', 'geeks'])
# Use fillna of complete Dataframe
# value function will be applied on every column
dframe.fillna(value = dframe.mean(), inplace = True)
print(dframe)
# filling value of one column
dframe['For'].fillna(value = dframe['For'].mean(),
inplace = True)
print(dframe)






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论