0

Sorry if this is a dumb question but I'm trying to import and open a CSV using pandas in Python. Whenever I hit run I get the syntax error "cannot import name 'unicode_literals'". I have no idea why that is happening and I haven't been able to find any source online which details what this error means.

This is my code:

import pandas as pd
with open(r"FILEPATH\File.csv") as rawData:
    pd.read_csv(rawData)

Here is the Error:

    C:\Anaconda3\python.exe "FILEPATH"
Traceback (most recent call last):
  File "FILEPATH/Main.py", line 1, in <module>
    import pandas as pd
  File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 7, in <module>
    from . import hashtable, tslib, lib
  File "pandas\src\numpy.pxd", line 157, in init pandas.hashtable (pandas\hashtable.c:22997)
  File "C:\Anaconda3\lib\site-packages\numpy\__init__.py", line 107, in <module>
    from __future__ import division, absolute_import, print_function
  File "C:\Anaconda3\lib\__future__.py", line 23, in <module>
    from __future__ import unicode_literals
ImportError: cannot import name 'unicode_literals'
cannot import name 'unicode_literals'

Any suggestions for why this isn't working would be greatly appreciated.

TheSaint321
  • 390
  • 2
  • 4
  • 17

1 Answers1

-1

You're on the right track! The only thing you have to do is add another parameter to open(). This would yield:

import pandas as pd
with open(r"FILEPATH\File.csv", encoding='utf-8') as rawData:
    pd.read_csv(rawData)
vbe419
  • 1
  • 2