热线电话:13121318867

登录
2018-12-18 阅读量: 1014
pandas如何填充缺失值?

填充缺失值:

现在,使用数据的均值或模式替换任何NaNfillna,可以根据需要替换特定列甚至整个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)

85.7143
4
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子