Python Pandas Error tokenizing data

后端 未结 30 2331
不知归路
不知归路 2020-11-22 04:49

I\'m trying to use pandas to manipulate a .csv file but I get this error:

pandas.parser.CParserError: Error tokenizing data. C error: Expected 2 field

30条回答
  •  情话喂你
    2020-11-22 05:36

    I had this problem, where I was trying to read in a CSV without passing in column names.

    df = pd.read_csv(filename, header=None)
    

    I specified the column names in a list beforehand and then pass them into names, and it solved it immediately. If you don't have set column names, you could just create as many placeholder names as the maximum number of columns that might be in your data.

    col_names = ["col1", "col2", "col3", ...]
    df = pd.read_csv(filename, names=col_names)
    

提交回复
热议问题