problem in reading products CSV file with pandas python

Question:

I have products CSV file and I am trying to read this file with pandas python but i get this error

my code

import pandas as pd
df = pd.read_csv('D:\work\amazon\move_in_links\final.csv')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:UsersCompu CityAppDataLocalProgramsPythonPython38libsite-packagespandasioparsers.py", line 676, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:UsersCompu CityAppDataLocalProgramsPythonPython38libsite-packagespandasioparsers.py", line 454, in _read
    data = parser.read(nrows)
  File "C:UsersCompu CityAppDataLocalProgramsPythonPython38libsite-packagespandasioparsers.py", line 1133, in read
    ret = self._engine.read(nrows)
  File "C:UsersCompu CityAppDataLocalProgramsPythonPython38libsite-packagespandasioparsers.py", line 2037, in read
    data = self._reader.read(nrows)
  File "pandas_libsparsers.pyx", line 860, in pandas._libs.parsers.TextReader.read
  File "pandas_libsparsers.pyx", line 875, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas_libsparsers.pyx", line 929, in pandas._libs.parsers.TextReader._read_rows
  File "pandas_libsparsers.pyx", line 916, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas_libsparsers.pyx", line 2071, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 7549, saw 8

this is the link of file


another thing when I deleted most of the rows and remain just 4 rows the file read.

Asked By: Eslam Tantawy

||

Answers:

By default pandas assumes your csv is separated by commas ',', you should pass the proper separator to the read_csv call.

import pandas as pd
df = pd.read_csv('D:\work\amazon\move_in_links\final.csv', sep=';')

https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html

Answered By: ScootCork

File appears to be separated by ;. Try:

import pandas as pd
df = pd.read_csv('D:\work\amazon\move_in_links\final.csv',sep=";")
Answered By: vmouffron

Follow these steps, this approach suggested by Ransaka works

Blockquote

use delimiter as; so you should pass external argument sep=’;. Try using df = pd.read_csv(‘YOUR_CSV_PATH’, sep=’;’)

Blockquote

And you can just use the file name as it is instead of a path.

Answered By: Elvira Khwatenge