Python数据科学包(六)-----数据可视化和例子

本文详细介绍了Python数据科学中的数据可视化,包括线型图、柱状图、直方图、密度图、散布图和饼图的绘制,并探讨了高级绘图功能。此外,还讲解了股票数据分析,涉及波动幅度、增长曲线、增长倍数和平均年化增长率的计算。同时,文章还提到了时间事件日志的读取、清洗和分析,以理解个人时间管理。
摘要由CSDN通过智能技术生成

一. 数据可视化

Pandas 的数据可视化使用 matplotlib 为基础组件。更基础的信息可参阅 matplotlib 相关内容。本节主要介绍 Pandas 里提供的比 matplotlib 更便捷的数据可视化操作。

1. 线型图

Series 和 DataFrame 都提供了一个 plot 的函数。可以直接画出线形图。

ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.describe()
ts.plot()
# ts.plot? for more help
ts.plot(title='cumsum', style='r-', ylim=[-30, 30], figsize=(4, 3));
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()
df.describe()
# df.plot? for more help
df.plot(title='DataFrame cumsum', figsize=(4, 12), subplots=True, sharex=True, sharey=True);
df['I'] = np.arange(len(df))
df.plot(x='I', y=['A', 'C'])

2. 柱状图

df = pd.DataFrame(np.random.rand(10, 4), columns=['A', 'B', 'C', 'D'])
df.ix[1].plot(kind='bar')
df.plot.barh(stacked=True)

3. 直方图

直方图是一种对值频率进行离散化的柱状图。数据点被分到离散的,间隔均匀的区间中,绘制各个区间中数据点的数据。

df = pd.DataFrame({
   'a': np.random.randn(1000) + 1, 'b': np.random.randn(1000),
                   'c': np.random.randn(1000) - 1}, columns=['a', 'b', 'c'])
df['a'].plot.hist(bins=10)
df.plot.hist(subplots=True, sharex=True, sharey=True)
df.plot.hist(alpha=0.5)
df.plot.hist(stacked=True, bins=20, grid=True)

4. 密度图

正态分布(高斯分布)就是一种自然界中广泛存在密度图。比如我们的身高,我们的财富,我们的智商都符合高斯分布。

df['a'].plot.kde()
df.plot.kde()
df.mean()
df.std()
n1 = np.random.normal(0, 1, size=200) # N(0, 1)
n2 = np.random.normal(10, 2, size=200
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值