股票数据分析——Python
程序员文章站
2022-06-04 17:15:19
...
# 导入工具包
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
import pandas_datareader as pdr
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
from datetime import datetime
# 时间
time=datetime(2018,10,12)
# 获取阿里巴巴与亚马逊的股票数据,开始时间为time
alibaba=pdr.get_data_yahoo("BABA",start=time)
amazon=pdr.get_data_yahoo("AMZN",start=time)
# 画阿里巴巴股票收盘价(Adj Close)的走势图
alibaba["Adj Close"].plot(kind="line",legend=True)
# 将列Adj Close更换列名
alibaba["Ali_Adu Close"]=alibaba["Adj Close"]
amazon["Ama_Adj Close"]=amazon["Adj Close"]
# 同时画阿里与亚马逊的股票收盘价走势图
alibaba["Ali_Adu Close"].plot(legend=True)
amazon["Ama_Adj Close