gh0strider18 gh0strider18 - 1 year ago 80
Python Question

Python file path failing in pycharm regex confusion

I am a relatively new python user and am getting a funky error using my IDE (pycharm), but not when using the cmd line.

Simply I:

path ='C:\Users\Dell\Downloads\users.dat'

import pandas as pd
unames = ['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table(path, sep='::', header=None, names=unames)

After which I receive an error that indicates:

ParserWarning: Falling back to the 'python' engine because the 'c' engine does not
support regex separators; you can avoid this warning by specifying engine='python'.

When i input the identical commands into the cmd line and print
the data prints as expected (i.e., no errors or anything funky).

EDIT: similarly when I input

ratingsdata ='C:\Users\Dell\Downloads\ratings.dat'

I get a funky
IOError: [Errno 22] invalid mode ('r') or filename:
Not sure as to why the
is not ok in a file path... I understand it's regex, but within the quoted lines??


Answer Source

Looks like on Python 2.7 Pandas just doesn't handle separators that look regexish. The initial "error" can be worked around by adding engine='python' as a named parameter in the call, as suggested in the warning.