python数据挖掘实验报告1
python数据挖掘实验报告1
实验内容及步骤(包含简要的实验步骤流程)
1.使用Pandas_datareader获取任意两支股票近三个月的交易数据。做出收盘价的变动图像。
2.使用Pandas_datareader获取世界银行数据库中美国(USA)、瑞典(SWE)、瑞士(CHE)三个国家近20年的NY.GDP.PCAP.KD数据,作图分析。
3.对于泰坦尼克的数据集,试分析幸存与否与独立登船的相关性(alone数据列)。
1.取五粮液(000858.sz)和古井贡酒(000596.sz)两只股票的三个月交易数据,做出收盘的变动图像。
#导入pandas_datareader/datetime/seaborn/matplotlib库
import pandas_datareader.data as webdata
import datetime
import seaborn as sns
import matplotlib.pyplot as plt
#处理Seaborn图表内嵌中文字体问题
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False
sns.set_style({'font.sans-serif':['simhei','Arial']})
#用datatime生成日期数据
start_time = datetime.datetime(2020,6,30)
end_time = datetime.datetime(2020,9,30)
#通过Yahoo财经,查询股票信息
stock_code1 = input('美股直接输入股票代码如GOOG \n港股输入代码+对应股市,如腾讯:0700.hk \n国内股票需要区分上证和深证,股票代码后面加.ss或者.sz\n你要查询的股票代码是:')
stock_info1 = webdata.get_data_yahoo(stock_code1,start_time,end_time)
#展示前5行
#print(stock_info1.head())
stock_code2 = input('另一只要查询的股票代码是:')
stock_info2 = webdata.get_data_yahoo(stock_code2,start_time,end_time)
#绘制股票价格波动图
print('股票收盘价对比:')
sns.set()
plt.figure(figsize=(10,4))
plt