python数据分析pandas画图_Pandas数据分析和matplotlib绘图

这篇博客介绍了如何使用Pandas的DataFrame和Series数据结构,结合matplotlib库进行数据分析和绘图。首先,展示了创建随机时间序列数据并进行累计求和,然后通过ts.plot()方法绘制图形,并保存为'scores_par.png'。接着,使用kaggle上的鸢尾花数据集,绘制了散点图和直方图,进一步展示了数据可视化的能力。
摘要由CSDN通过智能技术生成

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#

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值