问题描述
在学习《利用Python进行数据分析》第二章的时候,在处理Movielen文件,使用read_table()方法时,出现下述错误。问题代码与错误信息如下:
问题代码:
# 将三个表中的内容读入一个pandas DataFrame对象中
unames = ['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/users.dat',
sep='::', header=None, names = unames)
rnames = ['user_id', 'movie_id', 'rating', 'timestamp']
ratings = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/ratings.dat',
sep='::', header=None, names=rnames)
mnames = ['movie_id', 'title', 'genres']
movies = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/movies.dat',
sep='::', header=None, names=mnames)
错误信息:
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
解决方法
在上述使用read_table()方法的末尾加上 engine=’python’,即可:
# 将三个表中的内容读入一个pandas DataFrame对象中
unames = ['user_id', 'gender', 'age', 'occupation', 'zip']
users = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/users.dat',
sep='::', header=None, names = unames, engine='python')
rnames = ['user_id', 'movie_id', 'rating', 'timestamp']
ratings = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/ratings.dat',
sep='::', header=None, names=rnames, engine='python')
mnames = ['movie_id', 'title', 'genres']
movies = pd.read_table('C:/Users/yitian.z/Desktop/Python/pydata-book-master/ch02/movielens/movies.dat',
sep='::', header=None, names=mnames, engine='python')