美文网首页
pandas 练习示例

pandas 练习示例

作者: jiaxiaolei | 来源:发表于2020-05-06 11:47 被阅读0次

操作举例

In [2]: import matplotlib.pyplot as plt

In [3]: import numpy as np

In [4]: import pandas as pd

In [5]: df=pd.read_csv('/Users/jiaxiaolei/Desktop/london.csv')

In [6]: df
Out[6]:
    Year  Month  Tmax  Tmin  Rain   Sun
0   2018      1   9.7   3.8    58  46.5
1   2018      2   6.7   0.6    29  92.0
2   2018      3   6.7   0.6    29  92.0
3   2018      4   6.7   0.6    29  92.0
4   2018      5   6.7   0.6    29  92.0
5   2018      6   6.7   0.6    29  92.0
6   2018      7   6.7   0.6    29  92.0
7   2018      8   6.7   0.6    29  92.0
8   2018      9   6.7   0.6    29  92.0
9   2018     10   6.7   0.6    29  92.0
10  2018     11   6.7   0.6    29  92.0
11  2018     12   6.7   0.6    29  92.0

# 读取excel
In [39]: df=pd.read_excel('/Users/jiaxiaolei/Desktop/london.xls')

In [40]: df
Out[40]:
    Year  Month  Tmax  Tmin  Rain   Sun
0   2018      1   9.7   3.8    58  46.5
1   2018      2   6.7   0.6    29  92.0
2   2018      3   6.7   0.6    29  92.0
3   2018      4   6.7   0.6    29  92.0
4   2018      5   6.7   0.6    29  92.0
5   2018      6   6.7   0.6    29  92.0
6   2018      7   6.7   0.6    29  92.0
7   2018      8   6.7   0.6    29  92.0
8   2018      9   6.7   0.6    29  92.0
9   2018     10   6.7   0.6    29  92.0
10  2018     11   6.7   0.6    29  92.0
11  2018     12   6.7   0.6    29  92.0

In [7]: df.plot(x='Month',y='Tmax')
Out[7]: <matplotlib.axes._subplots.AxesSubplot at 0x11730f160>

In [8]: plt.show()


In [7]: df.plot(x='Month',y='Tmax', kind='line', grid=True)
Out[7]: <matplotlib.axes._subplots.AxesSubplot at 0x11d89f208>

In [8]: plt.show()


In [9]: df.plot(x='Month',y=['Tmax', 'Tmin'], kind='line', grid=True)
Out[9]: <matplotlib.axes._subplots.AxesSubplot at 0x11c8264e0>

In [10]: plt.show()


In [11]: df.plot(x='Month',y=['Tmax', 'Tmin'], kind='bar', grid=True)
Out[11]: <matplotlib.axes._subplots.AxesSubplot at 0x11d90b4e0>

In [12]: plt.show()



In [13]: df.plot(x='Month',y=['Tmax', 'Tmin'], kind='barh', grid=True)
Out[13]: <matplotlib.axes._subplots.AxesSubplot at 0x11d9bf908>

In [14]: plt.show()


# 散点图
In [20]: df.plot(x='Month',y=['Tmax'], kind='scatter')
Out[20]: <matplotlib.axes._subplots.AxesSubplot at 0x11dc05128>

In [21]: plt.show()

#NOTE:
这里使用  In [23]: df.plot(x='Month',y=['Tmax', 'Tmin'], kind='scatter')  多个纵轴 出现错误。

ValueError: x and y must be the same size


# 饼状图:
In [26]: df.plot(x='Month',y=['Sun'], kind='pie')
Out[26]: <matplotlib.axes._subplots.AxesSubplot at 0x122a3f710>

In [27]: plt.show()

# 关闭竖状图例
In [28]: df.plot(x='Month',y=['Sun'], kind='pie', legend=False)
Out[28]: <matplotlib.axes._subplots.AxesSubplot at 0x1203d6fd0>

In [29]: plt.show()

# 使用自定义的index
In [31]: df.index=['Jan','Feb', 'Mar','Apr','May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']

In [32]: df.plot(x='Month',y=['Sun'], kind='pie', legend=False)
Out[32]: <matplotlib.axes._subplots.AxesSubplot at 0x120a84d30>

In [33]: plt.show()


扩展阅读

使用pandas做数据可视化

https://mp.weixin.qq.com/s/d_EAPkeTPcnaSPPYS37qrg

简介:

示例很好...

实操性也比较好

相关文章

  • pandas 练习示例

    操作举例 扩展阅读 使用pandas做数据可视化 https://mp.weixin.qq.com/s/d_EAP...

  • pandas 中链式索引 选择数据1

    pandas 中链式索引 选择数据1 链式索引选择数据,示例1 +链式索引选择数据,示例2 链式索引选择数据,示例...

  • 爬虫分析之数据存储——基于MySQL,Scrapy

    上一篇->爬虫练习之数据整理——基于Pandas上上篇->爬虫练习之数据清洗——基于Pandas 配置MySql ...

  • pandas基础教程——Day4

    本章内容 pandas中的分组聚合 一、分组 二、聚合 示例: 拓展apply()函数

  • Pandas练习

    索引练习 索引是不能更常见的操作了。默认选取列,比如df['Date'],如果对行,用标签索引ix,如df.ix[...

  • pandas练习

    练习地址 以下是伪目录: 1、读取以及了解数据 2、筛选以及排序 3、分组 4、Apply 5、merge 6、s...

  • pandas练习

    https://github.com/ajcr/100-pandas-puzzles/blob/master/10...

  • pandas实例-总结

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Visualization-Titanic_D

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

  • pandas实例-Visualization-Scores

    继续前面的练习,之前的文章参考: pandas实例-了解你的数据-Chipotle pandas实例-筛选与排序-...

网友评论

      本文标题:pandas 练习示例

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