日常問題解決彙總

日常操作時遇到各種報錯或新想法,所遇問題以及搜索到的解決方案參考來源大彙總(持續更新)

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:

  1. The name of the entity was incorrect, for example using ‘APPL’ instead of ‘AAPL’.
  2. 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 下載庫時中途報錯,切換網絡重試

Markdown:

1. 正文序號下繼續分級,多空幾個空格可以實現

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章