import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdate
import datetime
设置最后画图时候的参数
# do all our graphics inline
%matplotlib inline
# Set some pandas options
pd.set_option('display.notebook_repr_html', False)
pd.set_option('display.max_columns', 6) # 设置显示的最大列数
pd.set_option('display.max_rows', 10) # 设置显示的最大行数
pd.set_option('display.width', 78) # 设置显示宽度
pd.set_option('precision', 3) # 设置精度为小数点后三位
写入路径
stockpath=r"F:\xxxxxxxxxxv"
读取csv文件
all_data=pd.read_csv(stockpath)
all_data
看一下数据大小
all_data.shape
选择需要的数据
all_data[["Ticker","Date","Adj Close"]]
通过上面的实例我们选取前十进行查看
just_close_price=all_data[["Ticker","Date","Adj Close"]]
just_close_price.head(10)
just_close_price.shape
看一下大小
just_close_price
just_close_price
接下来对数据进行透视,也就是分析
dialy_close_px=just_close_price.pivot("Date",
"Ticker",
"Adj Close") #透视,
提取索引
dialy_close_px.index #索引
提取列的信息
dialy_close_px.columns #列
我们可以选取AAPL的信息
dialy_close_px["AAPL"]
接下来就是绘制
dialy_close_px["AAPL"].plot(figsize=(12,8))