美文网首页
数学建模-数据分析中缺失值删除与缺失值处理方法(python)

数学建模-数据分析中缺失值删除与缺失值处理方法(python)

作者: 天帝之大 | 来源:发表于2019-07-31 21:24 被阅读0次

以下内容来源《python3破冰人工智能从入门到实战》,如涉及版权请联系我删除。

Python计算

Python 是一种面向对象的、动 态的程序设计语言,它具有非常简洁而清晰的语法,适合完成各种复杂任务。 并且,随着 NumPy、Pandas、SciPy、Matplotlib 等众多程序库的发布和发展, Python 越来越适合做科学计算。它既可以用来快速开发程序脚本,也可以用来开发大规模的软件。
内容来源《python3破冰人工智能从入门到实战》,

初识 Pandas

Pandas由AQR Capital Management于2008年开发,并于2009年底开源发布,目前由专 注于 Python 数据包开发的 PyData 开发团队继续开发和维护。本书中使用的版本是 Pandas-0.22.0。Pandas 基于 NumPy 开发,提供了大量快速便捷的数据处理方法,对数据的处 理工作十分有用,它是支撑 Python 成为强大而高效的科学计算语言的重要因素之一。
内容来源《python3破冰人工智能从入门到实战》,

Pandas构建数据

dates = pd.date_range("20130101",periods=6)
df = pd.DataFrame(np.random.rand(6,4),index=dates,columns=list
print("获取 df 数据:\n{}".format(df))

image.png

数据清洗

(1)缺失值处理与特殊值处理

df = pd.DataFrame(np.random.randint(1,10,[5,3]), index=['a', 'c', 'e', 'f', 'h'],colu mns=['one', 'two', 'three'])
df.loc["a","one"] = np.nan
df.loc["c","two"] = -99
   df.loc["c","three"] = -99
   df.loc["a","two"] = -100
   df['four'] = 'bar'
   df['five'] = df['one'] > 0
   df2 = df.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
   print(df2)

内容来源[《python3破冰人工智能从入门到实战》]


image.png

缺失值处理

#丢弃缺失值 dropna()
Input:
print("删除缺失值所在行(axis=0)或列(axis=1),默认为 axis=0,df2. dropna(axis=0)=\n{} ". format(df2.dropna(axis=0)))
image.png
image.png
image.png
image.png
image.png
image.png

数据的填充方法


image.png

参考文献:
来源数据《python3破冰人工智能从入门到实战》,如涉及版权请联系我删除。

相关文章

网友评论

      本文标题:数学建模-数据分析中缺失值删除与缺失值处理方法(python)

      本文链接:https://www.haomeiwen.com/subject/dtuxdctx.html