数据分析项目实战

数据分析项目实战_第1张图片

数据获取:1.主动获取--》爬虫   2.被动。api接口

                                                                      股票市场分析实战


数据分析项目实战_第2张图片

                                        通过pandas_datareader来获取数据

import pandas_datareader as pdr
import pandas as pd
#获取数据,不过yahoo的API不稳定
#alibaba = pdr.get_data_yahoo('BABA')
#alibaba.head()

现在从yahoo获取不了股票数据,我采用手动下载了csv格式的阿里巴巴的数据

alibaba = pd.read_csv("E:/BABA.csv")
#alibaba.head()
#alibaba.tail()
#alibaba.shape
alibaba.describe()

数据分析项目实战_第3张图片

                                                      股票市场分析实战之历史趋势分析

#基本信息
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
#股票数据的读取
import pandas_datareader as pdr
#time
from datetime import datetime
#可视化
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
'''
start = datetime(2015,9,20)
alibaba = pdr.get_data_yahoo('BABA', start = start)
alibaba.to_csv('E:/')
'''
alibaba = pd.read_csv('E:/BABA.csv')
#alibaba.head()
'''
历史趋势分析
'''
#alibaba['Adj Close'].plot(legend = True)  #最后价格
#alibaba['Volume'].plot(legend = True)
'''
每天之内最高价和最低价的变化
'''
alibaba['high-low'] = alibaba['High'] - alibaba['Low']
#alibaba['high-low'].plot()  
alibaba.set_index(['Date'], inplace = True) #把Date列作为index
'''
天和天的最高和最低的变化daily return
'''
alibaba['daily-return'] = alibaba['Adj Close'].pct_change()  #每天收盘的价格
#alibaba['daily-return'].plot(figsize = (10,4))
#通过直方图
#alibaba['daily-return'].plot(kind='hist')
#通过Seaborn绘图
#sns.distplot(alibaba['daily-return'].dropna(),bins=100,color='red') #dropna()去掉NAN
'''
风险分析
'''

start = datetime(2015,1,1)
#5家公司
company = ['AAPL','GOOG','MSFT','AMZN','FB']
top_tech_df = pdr.get_data_yahoo(company,start=start)['Adj Close']
top_tech_df.to_csv('E:/')
#top_tech_df.head()
top_tech_dr = top_tech_df.pct_change()

top_tech_df.pot()
top_tech_df[['AAPL','FB','MSFT']].plot #画出这三家公司的走势图


#Seanborn
sns.jointplot('AMZN','GOOG',top_tech_dr,kind='scatter')#谷歌和亚马逊的股票的增长散点图   只可以画x和y的对比.
#AMZN作为x轴,GOOG作为y轴

sns.pairplot(top_tech_dr.dropna()) #在x和y轴绘制多个图
数据分析项目实战_第4张图片

你可能感兴趣的:(Python基础)