0

I am pretty new to python and have never used pandas. I am wanting to extract data from a .csv file. Specifically, I would like to extract specific columns from the .csv file and turn them into lists in python. After doing some digging, it seems like pandas is the tool to use. However, I am getting stuck on my first line of code and getting more than a few errors.

import pandas as pd
df = pd.read_csv('RA197292-2 BDS1.csv')

These are the errors I am getting

Traceback (most recent call last):
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\main.py", line 38, in <module>
    df = pd.read_csv('RA197292-2 BDS1.csv')
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\venv\lib\site-packages\pandas\util\_decorators.py", line 311, in wrapper
    return func(*args, **kwargs)
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\venv\lib\site-packages\pandas\io\parsers\readers.py", line 680, in read_csv
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\venv\lib\site-packages\pandas\io\parsers\readers.py", line 581, in _read
    return parser.read(nrows)
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\venv\lib\site-packages\pandas\io\parsers\readers.py", line 1254, in read
    index, columns, col_dict = self._engine.read(nrows)
  File "C:\Users\mh104739\PycharmProjects\MDSRG_Dev\venv\lib\site-packages\pandas\io\parsers\c_parser_wrapper.py", line 225, in read
    chunks = self._reader.read_low_memory(nrows)
  File "pandas\_libs\parsers.pyx", line 805, in pandas._libs.parsers.TextReader.read_low_memory
  File "pandas\_libs\parsers.pyx", line 861, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 847, in pandas._libs.parsers.TextReader._tokenize_rows
  File "pandas\_libs\parsers.pyx", line 1960, in pandas._libs.parsers.raise_parser_error
pandas.errors.ParserError: Error tokenizing data. C error: Expected 1 fields in line 4, saw 2


Process finished with exit code 1

Things I have tried

I have added an r in front of my file name.

I have passed the entire file path but my.csv file is in the same folder as my .py file so I am not sure that would do anything anyways.

I have increased my heap to like 20gb in PyCharm.

I have tried other IDEs.

I have banged my head against my desk

I have successfully read the file using the csv module but I am not really sure how to extract columns from the file to begin to manipulate the data. Looking for answers to that question is what lead me to pandas.

Any ideas?

  • 1
    `Error tokenizing data. C error: Expected 1 fields in line 4, saw 2` The csv contains too many delimiters in the line reported. If your file is comma-delimited, for example, one of the data elements has a comma in the middle (like 1,000 for example) – G. Anderson May 20 '22 at 19:37
  • 1
    Thanks for the help. I believe my issue was that there were 4 rows that each only contained one element before the header row. Thanks a million! – Radical Edward May 20 '22 at 19:52

0 Answers0