Black Lives Matter. Please consider donating to Black Girls Code today.

Error while reading CSV file with pd.read_csv

Hi there!

I am in troubles with reading a CSV via https. Following code is NOT working:

filedata = 'https://github.com/pcm-dpc/COVID-19/blob/master/dati-province/dpc-covid19-ita-province-latest.csv'
import pandas as pd
df = pd.read_csv(filedata,
                   dtype={"denominazione_provincia": str})

While following code IS working (taken from here :

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
                   dtype={"fips": str})

This is the error msg I get… Anyone can help?


Traceback (most recent call last):

  File "<ipython-input-105-19a69f730c06>", line 4, in <module>
    dtype={"denominazione_provincia": str})

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 676, in parser_f
    return _read(filepath_or_buffer, kwds)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 454, in _read
    data = parser.read(nrows)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 1133, in read
    ret = self._engine.read(nrows)

  File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\io\parsers.py", line 2037, in read
    data = self._reader.read(nrows)

  File "pandas\_libs\parsers.pyx", line 859, in pandas._libs.parsers.TextReader.read

  File "pandas\_libs\parsers.pyx", line 874, in pandas._libs.parsers.TextReader._read_low_memory

  File "pandas\_libs\parsers.pyx", line 928, in pandas._libs.parsers.TextReader._read_rows

  File "pandas\_libs\parsers.pyx", line 915, in pandas._libs.parsers.TextReader._tokenize_rows

  File "pandas\_libs\parsers.pyx", line 2070, in pandas._libs.parsers.raise_parser_error

ParserError: Error tokenizing data. C error: Expected 1 fields in line 49, saw 2

Hi @Alex79 welcome to the forum! This is clearly a pandas question so you would probably get more help on Stackoverflow (the pandas github says that pandas questions should be asked on Stackoverflow). That said, the error message says that there is a problem with your csv file. You should download it, open it in a text editor and see what’s wrong with line 49 (or more generally inspect the structure of the file). Good luck!

Thank you Emmanuelle 4 welcoming and replying!
I’ll try your suggestion asap.
Best, A.