Home > OS >  Python: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 21, saw
Python: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 21, saw

Time:12-03

I know where this error is coming from.

I try to df = pd.read_csv("\words.csv")

In this csv, I have a column with each row filled with text. Sometimes in this text, I have this separator a comma ,. enter image description here

But I have pratically all the possible symbols so I can't give it a good separator ! (I have ; too)

The only thing that I know is that I only need 1 column. Is there a way to force the number of columns and not interpret the others "separators" ?

CodePudding user response:

Since you are aiming to have one column, one way to achieve this goal is to use a newline \n as a separator like so:

import pandas as pd

df = pd.read_csv("\words.csv", sep="\n")

Since there will always be one line per row it is bound to always detect one column.

  • Related