1

I try to read a csv file I have read and write access to into a dataframe using pandas under Win10 within Visual Code. What I have tried yet is:

df1 = pd.read_csv("C:\\Users\\me\\Desktop\\Python\\Analytics\\in\\test_DS.csv", sep=';', header = None)

df1 = pd.read_csv(r"C:\Users\me\Desktop\Python\Analytics\in\test_DS.csv", sep=';', header = None)

df1 = pd.read_csv(r"C:/Users/me/Desktop/Python/Analytics/in/test_DS.csv", sep=';', header = None)

But I still get the Error: Unable to open parsers.pyx File not found in C:/Users/me/Desktop/Python/Pandas/_libs/parsers.pyx.

Can anyone tell me what I am doing wrong here?

******************Traceback To get a Traceback I implemented:

except Exception:
        print("Exception in user code:")
        print("-"*60)
        traceback.print_exc(file=sys.stdout)
        print("-"*60)

I got:

Exception in user code:

------------------------------------------------------------

Traceback (most recent call last):
  File "pandas\_libs\parsers.pyx", line 1169, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas\_libs\parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas\_libs\parsers.pyx", line 1315, in pandas._libs.parsers.TextReader._string_convert
  File "pandas\_libs\parsers.pyx", line 1553, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 10: invalid start byte

During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "c:\Users\me\Desktop\Python\GPTW-Analytics\py\main.py", line 22, in <module>
    df1 = pd.read_csv('C:/Users/me/Desktop/Python/GPTW-Analytics/in/test_DS.csv', sep=';')
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 702, in parser_f
    return _read(filepath_or_buffer, kwds)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 435, in _read
    data = parser.read(nrows)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1139, in read
    ret = self._engine.read(nrows)
  File "C:\Users\me\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\parsers.py", line 1995, in read
    data = self._reader.read(nrows)
  File "pandas\_libs\parsers.pyx", line 899, in pandas._libs.parsers.TextReader.read
  File "pandas\_libs\parsers.pyx", line 914, in pandas._libs.parsers.TextReader._read_low_memory
  File "pandas\_libs\parsers.pyx", line 991, in pandas._libs.parsers.TextReader._read_rows
  File "pandas\_libs\parsers.pyx", line 1123, in pandas._libs.parsers.TextReader._convert_column_data
  File "pandas\_libs\parsers.pyx", line 1176, in pandas._libs.parsers.TextReader._convert_tokens
  File "pandas\_libs\parsers.pyx", line 1299, in pandas._libs.parsers.TextReader._convert_with_dtype
  File "pandas\_libs\parsers.pyx", line 1315, in pandas._libs.parsers.TextReader._string_convert
  File "pandas\_libs\parsers.pyx", line 1553, in pandas._libs.parsers._string_box_utf8
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfc in position 10: invalid start byte
------------------------------------------------------------
ruedi
  • 5,365
  • 15
  • 52
  • 88
  • Possible duplicate of [Error while reading a csv file in python using pandas](https://stackoverflow.com/questions/38336501/error-while-reading-a-csv-file-in-python-using-pandas) – roganjosh May 11 '19 at 12:52
  • The solution of this SO Problem comprises: you can use always: 'C:/mydir' this is obviouisly not working in my case or at least giving me an error as stated. – ruedi May 11 '19 at 12:58
  • And `df1 = pd.read_csv("C:/Users/me/Desktop/Python/Analytics/in/test_DS.csv", sep=';', header = None)`, without the `r`? – roganjosh May 11 '19 at 12:59
  • traceback please. – thebjorn May 11 '19 at 13:00
  • not working. I have left the header = none and changed ' to " even though this should have an impact. Still getting the same error – ruedi May 11 '19 at 13:01
  • I added the traceback (hope I got that right) – ruedi May 11 '19 at 13:11

2 Answers2

1

I had this same issue today and reinstalls of pandas and numpy didn't help. Then I realized my separator was wrong; fixing that corrected the issue. Worth checking?

Also, your traceback makes it look like there could be corruption in the file; perhaps post the top of the file as well here for debugging.

T. Shaffner
  • 359
  • 1
  • 5
  • 22
-1

That is the old question, but in case someone googled it as am I. In my case that was an issue with encoding - file was opened as utf-8 though correct encoding was 1251