Reputation: 1
I am learning Python from 'Python for Finance' and the packages used are outdated. Please help me out with the following error: It shows EmptyDataError: No columns to parse from file.
import pandas as pd
url1 = 'http://hopey.netfonds.no/posdump.php?'
url2 = 'date=%s%s%s&paper=AAPL.O&csv_format=csv'
url = url1 + url2
year = '2017'
month = '11'
days = ['9']
AAPL = pd.DataFrame()
for day in days:
AAPL = AAPL.append(pd.read_csv(url % (year, month, day),
index_col=0, header=0, parse_dates=True))
AAPL.columns = ['bid', 'bdepth', 'bdeptht','offer', 'odepth', 'odeptht']
Error:
EmptyDataError: No columns to parse from file
Upvotes: 0
Views: 1857
Reputation: 447
This error is caused by a Pandas issue.
posdump.php
script will send HTTP response like: HTTP/1.1 200 OK
Date: Tue, 22 May 2018 01:18:42 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.25
Content-Disposition: attachment; filename=exams.csv
Pragma: no-cache
Expires: 0
Content-Type: text/csv
It means content is sent in an attachment named filename exams.csv
.
To fix this, report this issue to pandas team.
For a workaround, please use requests
module to get the content as string, then read in with pandas:
from io import StringIO
import pandas as pd
import requests
url = 'https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv'
s = requests.get(url).text
c = pd.read_csv(StringIO(s))
Upvotes: 1