Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python file path failing in pycharm regex confusion

Tags:

python

regex

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'.
ParserWarning)

When i input the identical commands into the cmd line and print users 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 /r is not ok in a file path... I understand it's regex, but within the quoted lines??

Help!

like image 415
gh0strider18 Avatar asked Nov 29 '22 01:11

gh0strider18


1 Answers

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.

like image 129
Nathan Tuggy Avatar answered Dec 06 '22 06:12

Nathan Tuggy