日常操作時遇到各種報錯或新想法,所遇問題以及搜索到的解決方案參考來源大彙總(持續更新)
Python數據科學庫
1. URLError: <urlopen error [Errno 61] Connection refused>
# 原代碼
import seaborn as sns
planets = sns.load_dataset('planets')
解決:從github下載數據集,用pandas調用
import pandas as pd
planets = pd.read_csv('./seaborn-data-master/planets.csv')
2. Keyerror: ‘Date’
I received the ‘Keyerror ‘Date’ when using pandas datareader’ error and found two errors in my script that fixed the issue:
- The name of the entity was incorrect, for example using ‘APPL’ instead of ‘AAPL’.
- There was no data for the date parameters I was using.
# 解決代碼
# Use 'BTC-USD' stock/security value
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
start = dt.datetime(2017, 1, 1)
end = dt.datetime(2019, 11, 30)
df = web.DataReader('BTC-USD', 'yahoo', start, end)
df.to_csv('BTC.csv')
print(df.head())
- 如不確定數據集起始時間也可以設置時間,如下
yhoo = data.DataReader('BTC-USD', data_source='yahoo')
yhoo.head()
yhoo.tail()
- 可以看出數據集起始時間是2015年至2020年
3. NotImplementedError: data_source=None is not implemented
# 原代碼
from pandas_datareader impoart data
goog = data.DataReader('GOOG', start='2004', end='2016')
goog.head()
As of v0.7.0 Google finance and Morningstar have been immediately deprecated due to large changes in their API and no stable replacement.
終端:
1. pip install 下載庫時中途報錯,切換網絡重試
- 詭異的錯誤:OpenSSL.SSL.Error: [(‘SSL routines’, ‘ssl3_get_record’, ‘decryption failed or bad record mac’)