苹果股票分析-python时间序列

# -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
def quarter_volume():
    data=pd.read_csv("/Users/liyili2/Downloads/shiyanlou/apple.csv",header=0)
    print(data.head())
    # 将 Date 列转换为时间索引
    data.Date = pd.to_datetime(data['Date'])
    # 读取 Volume 列数据,并添加索引
    data_Volume=pd.Series(data['Volume'].values,index=data.Date)
    # 使用 Offset='Q' 参数,可以直接按季度重采样
    data_Q=data_Volume.resample('Q').sum()
    # 对交易数据从大到小排序后,返回第二项数据
    result=data_Q.sort_values(ascending=False)
    print(result)
    second_volume=result[1]
    # 完善代码

    return second_volume

if __name__ == "__main__":
    second_volume=quarter_volume()
    print("交易第二的季度总量是:",second_volume)
     Date   Open   High    Low  Close     Volume

0 2009-01-02 12.27 13.01 12.17 12.96 188749470
1 2009-01-05 13.31 13.74 13.24 13.51 297211453
2 2009-01-06 13.71 13.88 13.20 13.29 323043903
3 2009-01-07 13.12 13.21 12.89 13.00 189300706
4 2009-01-08 12.92 13.31 12.86 13.24 168365988
Date
2009-03-31 11883325286
2010-06-30 11625428360
2011-09-30 9785249544
2010-03-31 9525718538
2012-12-31 9302392372
2010-09-30 9278493119
2012-06-30 8640892029
2009-06-30 8489954543
2012-03-31 8454128130
2009-12-31 8202240823
2013-03-31 7911378167
2011-03-31 7860484814
2009-09-30 7275334241
2010-12-31 7183137346
2011-12-31 7104708093
2013-06-30 6856687985
2012-09-30 6596663815
2011-06-30 6358325057
2013-09-30 5807850762
2013-12-31 5030481085
2014-03-31 4929100988
2014-06-30 4250437446
2015-09-30 3852541741
2015-03-31 3580441016
2014-09-30 3500426543
2014-12-31 3254527713
2015-06-30 2828894478
2016-03-31 2798550288
2015-12-31 2758062705
2016-06-30 2525159344
2016-09-30 2285537326
2016-12-31 2016573431
dtype: int64
交易第二的季度总量是: 11625428360

你可能感兴趣的:(苹果股票分析-python时间序列)