热线电话:13121318867

登录
2019-06-18 阅读量: 658
pandas如何填充缺失值

使用填充缺失值fillna()replace()interpolate()

为了填充数据集中的空值,我们使用fillna()replace()并且interpolate()函数这些函数将NaN值替换为它们自己的某个值。所有这些功能都有助于在DataFrame的数据集中填充空值。Interpolate()函数主要用于填充NA数据帧中的值,但它使用各种插值技术来填充缺失值,而不是对值进行硬编码。

代码#:

# importing pandas as pd

import pandas as pd

# importing numpy as np

import numpy as np

# dictionary of lists

dict = {'First Score':[100, 90, np.nan, 95],

'Second Score': [30, 45, 56, np.nan],

'Third Score':[np.nan, 40, 80, 98]}

# creating a dataframe from dictionary

df = pd.DataFrame(dict)

# filling missing value using fillna()

df.fillna(0)

输出:

0.0000
2
关注作者
收藏
评论(0)

发表评论

暂无数据
推荐帖子