以下内容来源《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))
![](https://img.haomeiwen.com/i7583980/84f9095eed8d53eb.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破冰人工智能从入门到实战》]
![](https://img.haomeiwen.com/i7583980/8286c7154d2070f6.png)
缺失值处理
#丢弃缺失值 dropna()
Input:
print("删除缺失值所在行(axis=0)或列(axis=1),默认为 axis=0,df2. dropna(axis=0)=\n{} ". format(df2.dropna(axis=0)))
![](https://img.haomeiwen.com/i7583980/aa72402899ae778d.png)
![](https://img.haomeiwen.com/i7583980/ab60d2f4ec1417ae.png)
![](https://img.haomeiwen.com/i7583980/b19005ef90ac2a9d.png)
![](https://img.haomeiwen.com/i7583980/785a45a466bcc7c8.png)
![](https://img.haomeiwen.com/i7583980/ba1b4c04a03e9366.png)
![](https://img.haomeiwen.com/i7583980/84e0a1bef444c30a.png)
数据的填充方法
![](https://img.haomeiwen.com/i7583980/8f976121900c3b20.png)
参考文献:
来源数据《python3破冰人工智能从入门到实战》,如涉及版权请联系我删除。
网友评论