Pandas的主要数据结构:
Series,
DataFrame,
Panel
1、引入模块
import pandas as pd #数据分析,代码基于numpy
import numpy as np #处理数据,代码基于ndarray
import matplotlib.pyplot as plt #画图
2、绘图
>>> ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
Freq: D, Length: 1000, dtype: float64
>>> ts = ts.cumsum()
>>> ts
2000-01-01 0.152850
2000-01-02 1.723377
2000-01-03 0.531326
2000-01-04 1.511599
2000-01-05 -0.238038
2000-01-06 0.248185
2000-01-07 0.705009
2000-01-08 2.037722
2000-01-09 2.552921
2000-01-10 1.056137
2000-01-11 2.200608
2000-01-12 3.012396
2000-01-13 4.091995
2000-01-14 2.817742
2000-01-15 2.720006
2000-01-16 3.010116
2000-01-17 2.823765
2000-01-18 2.891493
2000-01-19 4.680008
2000-01-20 5.643906
2000-01-21 4.725293
2000-01-22 4.240956
2000-01-23 5.941939
2000-01-24 5.857652
2000-01-25 3.326831
2000-01-26 4.871872
2000-01-27 6.569036
2000-01-28 8.743762
2000-01-29 8.617857
2000-01-30 7.116748
...
2002-08-28 66.163787
2002-08-29 66.307171
2002-08-30 65.923158
2002-08-31 65.181081
2002-09-01 67.340244
2002-09-02 65.529171
2002-09-03 66.262337
2002-09-04 66.951161
2002-09-05 65.889828
2002-09-06 65.622222
2002-09-07 66.071755
2002-09-08 66.365986
2002-09-09 66.038691
2002-09-10 63.875978
2002-09-11 64.429092
2002-09-12 66.087279
2002-09-13 65.108901
2002-09-14 65.303637
2002-09-15 66.157815
2002-09-16 65.966299
2002-09-17 65.365800
2002-09-18 63.798020
2002-09-19 63.532243
2002-09-20 62.891584
2002-09-21 64.979569
2002-09-22 64.529803
2002-09-23 65.482294
2002-09-24 64.968179
2002-09-25 63.684175
2002-09-26 63.334510
Freq: D, Length: 1000, dtype: float64
>>> ts.plot()
>>> plt.savefig('scores_par.png') ##保存图片到当前目录
>>> plt.show()
3、利用kaggle上iris花的数据分析图形可视化
# 首先载入pandas
import pandas as pd
import matplotlib.pyplot as plt
# 载入数据
iris = pd.read_csv("Iris.csv") # 数据现在为 DataFrame格式
##散点图
iris.plot(kind="scatter", x="SepalLengthCm", y="SepalWidthCm")
plt.savefig('scatter.png')
plt.show()
## 直方图
参考资料:
http://python.jobbole.com/87136/
https://www.kaggle.com/uciml/iris
http://pandas.pydata.org/pandas-docs/stable/10min.html#