Pandas数据分析初学--时间序列

本文通过使用Pandas库,详细解析了Apple公司从1980年至2014年的股价数据,包括数据导入、预处理、数据类型检查、时间序列操作、统计分析及可视化等关键步骤。

探索Apple公司股价数据

首先导入Pandas库

import pandas as pd

(1). 读取数据并存为一个名叫apple的数据框。

apple = pd.read_csv('appl_1980_2014.csv')

(2). 查看每一列的数据类型。

apple.dtypes

(3). 将Date这个列转换为datetime类型。

apple.Date = pd.to_datetime(apple.Date)

(4). 将Date设置为索引。

apple = apple.set_index('Date')

(5). 有重复的日期吗?

apple.index.is_unique

(6). 将index设置为升序。

apple = apple.sort_index(ascending = True)

(7). 找到每个月的最后一个交易日(businessday)。

apple_month = apple.resample('BM').mean()
apple_month.head()

(8). 数据集中最早的日期和最晚的日期相差多少天?

(apple.index.max() - apple.index.min()).days

(9). 在数据中一共有多少个月?

len(apple_month)

(10). 按照时间顺序可视化AdjClose值。

apple['Adj Close'].plot(title = 'Apple Stock').get_figure().set_size_inches(9,5)

数据表Github链接:https://github.com/Booting-O/Pandas-Practice.git

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值