[Solved] C error: expected 1 fields in line 3, saw 2 processing method

1. There is a CSV file that I read directly with the pandas library, and an error is reported: error tokenizing data. C error: expected 1 fields in line 3, saw 2. There should be a problem with the format. It can only be opened after it is opened and saved again. However, because there are many files, I wonder if I can read the CSV file by other methods;

2. Read through the CSV library, traverse, and merge:

import pandas as pd
import csv


path = 'the location of file'

test = pd.DataFrame()
data = csv.reader(open(path, 'r'))
for d in data:
    # print(d)
    result = pd.DataFrame(d).T
    test = pd.concat([test,result])
test = test.reset_index(drop = True)

3. Finally, you will get the dataframe of test, which is the same as the file read by pandas after saving

Read More: