美文网首页
苹果公司股票时间序列分析

苹果公司股票时间序列分析

作者: 一天天111 | 来源:发表于2019-10-21 12:36 被阅读0次

要求:

得到交易总量排名第二的季度,并返回该季度的成交总量。

分析:

1.时间处理--使用pandas时间序列
2.季度重采样-可以将数据转化为pd.Series,然后使用:resample('W').sum()。
3.第二:排序倒序,取第二个。

代码实现:

import pandas as pd
from sklearn.ensemble import RandomForestClassifier


data=pd.read_csv('/Users/liyili2/Downloads/datas/apple.csv', header=0)
'''
成交日期(Date)、开盘价格(Open)、最高价格(High)、最低价格(Low)、
收盘价格(Close)、当天交易量(Volume)
'''
df=data[['Date','Volume']]
df.head()
df_Date=data['Date'].values
index=pd.to_datetime(df_Date)
df_Volume=df['Volume'].values
df_final=pd.Series(df_Volume,index=index)
df_final.resample('Q').sum()
result=df_final.sort_values(ascending=False)[1]

相关文章

网友评论

      本文标题:苹果公司股票时间序列分析

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