import pandas as pd import numpy as np import matplotlib.pyplot as plt
pd.set_option('display.width',1000)
url = 'https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/09_Time_Series/Apple_Stock/appl_1980_2014.csv' apple = pd.read_csv(url)
print(apple.head())
print(apple.dtypes)
apple['Date'] = pd.to_datetime(apple.Date) print(apple.dtypes)
apple = apple.set_index('Date') print(apple.head())
print(apple.index.is_unique)
apple = apple.sort_index(ascending=True) print(apple.head())
apple_month = apple.resample('BM').mean() print(apple_month.head())
print((apple.index.max()-apple.index.min()).days)
print(len(apple.index))
apple_months = apple.resample('BM').mean() print(len(apple_months.index))
apple_open = apple['Adj Close'].plot(title = 'Apple Stock') fig = apple_open.get_figure() fig.set_size_inches(13.5,9) plt.show()
本文由 所长 创作,采用 知识共享署名4.0 国际许可协议进行许可 本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名 最后编辑时间为: Apr 24, 2018 at 07:26 am