Python3.6.4必須downgrade成3.5
pip版本最低9.0.3
自己的電腦必須已經安裝好git
關于anaconda prompt報錯“Cannot find command 'git'”解決
在anaconda prompt執行
1
|
conda install pandas - datareader |
報錯,讀prompt的錯誤,執行它提示的命令,把Python3.6.4降級成3.5,pip升級成9.0.3,過程有點長,5 6分鐘。
(有點不太理解的是,Python降級后,我的程序與功能里顯示的還是3.6.4 ↓
可能只是在anaconda里降級了?不懂)
電腦已經安裝好git,在git bash里執行
1
|
git clone https: / / github.com / pydata / pandas - datareader.git |
執行完畢后,在anaconda prompt里執行
1
|
pip install git + https: / / github.com / pydata / pandas - datareader.git |
(因為開始我沒有在git bash安裝pandas-datareader就直接執行這一步,一直報Cannot find command 'git'”錯,我就把git添加到環境變量了,不知道后來有沒有幫助)
執行完畢,就可以使用Python獲取Yahoo的金融數據了。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
# 使用Yahoo Finance的API獲取四個公司的股票數據 import pandas as pd import numpy as np from pandas_datareader import data codes = [ 'AAPL' , 'IBM' , 'MSFT' , 'GOOG' ] # 四個股票 all_stock = {} for ticker in codes: all_stock[ticker] = data.get_data_yahoo(ticker,start = '1/1/2018' , end = '30/3/2018' ) # 默認從2010年1月起始 volume = pd.DataFrame({tic: data[ 'volume' ] for tic, data in all_stock.items()}) open = pd.DataFrame({tic: data[ 'open' ] for tic, data in all_stock.items()}) high = pd.DataFrame({tic: data[ 'high' ] for tic, data in all_stock.items()}) low = pd.DataFrame({tic: data[ 'low' ] for tic, data in all_stock.items()}) close = pd.DataFrame({tic: data[ 'close' ] for tic, data in all_stock.items()}) price = pd.DataFrame({tic: data[ 'adjclose' ] for tic, data in all_stock.items()}) # 已調整或者復權后的收盤價,能比較真實反映股票的表現 |
補充:pip通過setup.py和git倉庫安裝package
安裝setup.py配置文件中的包
進入到setup.py所在目錄
1
|
pip install - e . |
安裝git倉庫中的包
1
|
pip install git + git clone 倉庫地址.git |
python代碼打包為whl格式
1
|
python setup.py bdist_wheel - - universal |
通過setup.py直接安裝包
1
2
|
python setup.py build python setup.py install |
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持服務器之家。如有錯誤或未考慮完全的地方,望不吝賜教。
原文鏈接:https://blog.csdn.net/m0_37663482/article/details/79732429