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:
- Pandas Read csv Error tokenizing data. C error: Expected 18 fields in line 173315, saw 20
- [Solved] Pylint Warning: An attribute defined in json.encoder line 158 hides this methodpylint(method-hidden)
- Chromdriver Install error: File “C:\python37\lib\site-packages\selenium\webdriver\common\service.py”, line 76, in start stdin=PIPE) File…
- [Solved] Django Access to the backend error: Invalid block tag on line 98: ‘trans‘, expected ‘elif , ‘else‘或‘ endif. Did you forget
- Typeerror in Python regular expression: expected string or bytes like object
- Panda error in modifying line name index does not support mutable operations
- The Python DOM method iterates over all the XML in a folder
- How does Python output colored fonts in the CMD command line window
- How to Fix Errors encountered in executing Python scripts with command line parameters
- Parallel processing in Python (Pool.map(), Pool.starmap(), Pool.apply ())
- [Solved] PyQt: RuntimeError: wrapped C/C++ object has been deleted & has no attribute of flush in python
- ValueError: Found array with dim 4. Estimator expected and ValueError: Expected 2D array, got 1D array i
- python: File Processing and Input and Output
- Python installs virtualenv through PIP and always reports an error: response.py“, line 438, in _error_catcher yield
- Python: The behavior of this method will change in future versions
- [Solved] RuntimeError: scatter(): Expected dtype int64 for index
- [Solved] RuntimeError: unexpected EOF, expected 73963 more bytes. The file might be corrupted.
- [Solved] Django backend processing Base64 file upload error
- [Solved] Error: [email protected]: wrong number of arguments (given 1, expected 0)
- Python RuntimeError: Expected 4-dimensional input for 4-dimensional weight [32, 1, 5, 5]