0
我想從網站上讀取csv文件。該鏈接存在,但它會引發錯誤<urlopen錯誤[Errno 54]通過對等方重置連接>
我的代碼是:
pd.read_csv("https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.csv")
和錯誤是:
<urlopen error [Errno 54] Connection reset by peer>
。
更新:我嘗試了另一個鏈接,使用較小的數據集,它執行沒有問題。我想,也許是錯誤的,由於數據集較大,導致錯誤。
那麼如何處理上面的鏈接呢?
您是否嘗試過使用'requests'並在讀取數據框之前先獲取文件的內容? '進口要求;從io import StringIO;將pandas導入爲pd; pd.read_csv(StringIO的(requests.get( 「https://data.cityofnewyork.us/api/views/kku6-nxdu/rows.csv」).content.decode( 'UTF8')))'。那樣有用嗎? – Abdou
@Abdou我現在嘗試了代碼,這一次它說'ConnectionError:('Connection aborted。',ConnectionResetError(54,'Connection reset by peer'))' –
看看[this](https:// github.com/kennethreitz/requests/issues/3189)。這可能對您有所幫助。 – Abdou