1

I am getting a csv file from a url and I am trying to read it using pandas.read_csv with Python3, but I am getting a parserError for some reason. Here's the code:

csvurl = requests.get("https://github.com/cs109/2014_data/blob/master/countries.csv")
csvb = BytesIO(csvurl.content)
countries = pd.read_csv(csvb)

and I am getting the following error:

ParserError: Error tokenizing data. C error: Expected 1 fields in line 114, saw 3

But line 114 is just the same as the other lines. Is the error related to me trying to read csv using Bytes object?

Adrien Brunelat
  • 4,492
  • 4
  • 29
  • 42

1 Answers1

3

Use raw data url only:

url = 'https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv'
countries = pd.read_csv(url)
print (countries)

                              Country         Region
0                             Algeria         AFRICA
1                              Angola         AFRICA
2                               Benin         AFRICA
3                            Botswana         AFRICA
4                             Burkina         AFRICA
5                             Burundi         AFRICA
6                            Cameroon         AFRICA
7                          Cape Verde         AFRICA
8            Central African Republic         AFRICA
9                                Chad         AFRICA
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Even using the url in this way is producing the same ParseError. – Sarvesh Kesharwani Nov 20 '17 at 13:21
  • There is no problem with some firewall? Or some typo in url? Please check `pd.read_csv('https://raw.githubusercontent.com/cs109/2014_data/master/countries.csv')`. It should works. – jezrael Nov 28 '17 at 07:16