Han Zhengzu
Han Zhengzu

Reputation: 3842

Read csv online with error Error tokenizing data

The datafile in the format of .csv can successfully readed in the local computer.

df = pd.read_csv("./data.csv") 

enter image description here

The file is upload here.

However, I use two method with the uploading data in Dropbox or Github, the reading process all occured error as follows:

df = pd.read_csv("https://www.dropbox.com/s/2ew62yi0v07tjub/data-1.csv?dl=0")     

error: pandas/parser.pyx in pandas.parser.TextReader.read (pandas/parser.c:10364)() pandas/parser.pyx in pandas.parser.TextReader._read_low_memory (pandas/parser.c:10640)() pandas/parser.pyx in pandas.parser.TextReader._read_rows (pandas/parser.c:11386)() pandas/parser.pyx in pandas.parser.TextReader._tokenize_rows (pandas/parser.c:11257)() pandas/parser.pyx in pandas.parser.raise_parser_error (pandas/parser.c:26979)() CParserError: Error tokenizing data. C error: Expected 1 fields in line 3, saw 2

df = pd.read_csv("https://github.com/envhyf/Notebook/blob/master/data-1.csv")  

CParserError: Error tokenizing data. C error: Expected 1 fields in line 116, saw 3

Thus, my question is why the csv file can be read in my own computer, but failed in the cloud?

How to fix this problem. I have tried the answer of this question by adding error_bad_lines=False. But it didn't work for me.

Upvotes: 1

Views: 1019

Answers (1)

jezrael
jezrael

Reputation: 862581

For github you can use raw data:

df = pd.read_csv("https://raw.githubusercontent.com/envhyf/Notebook/master/data-1.csv")

And for dropbox need dl=1, info from this:

df = pd.read_csv("https://www.dropbox.com/s/gcn75c65222dtfk/data-1.csv?dl=1")

Upvotes: 1

Related Questions