简体   繁体   中英

There is a error while opening the file: Error tokenizing data

#importing libraries
import sys
import os
import numpy as np
import pandas as pd
import csv

#main function
if __name__ == "__main__":
    user_input=sys.argv[0]
    user_input1=sys.argv[1:]
    sample=pd.read_csv(user_input)
    filename=user_input1

#initializing empty list for appending column values of data-type file
    list1 = []
    list2 = []
    with open(filename,'r',newline="") as f:
        reader=csv.DictReader(f)

There is error: pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 19, saw 3. How to resolve this error

You could try the following code

sample = pd.read_csv('Filename', error_bad_lines=False)

This could also be an issue of delimited in csv files. So try this if the above code doesnt work for you

sample=pd.read_csv('Filename', sep='\t')

and place this line of code after the filename command

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM