解决ParserWarning: you can avoid this warning by specifying engine=’python’问题

问题描述

在学习《利用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')

 

C:\Users\HP\PycharmProjects\pythonProject\Python 试验.py:2: ParserWarning: Falling back to the 'python' engine because the 'c' engine does not support skipfooter; you can avoid this warning by specifying engine='python'. df = pd.read_csv('D:\\A过铁精矿\\ related.txt', header=None, skiprows=1, skipfooter=1, delimiter='\t') Traceback (most recent call last): File "C:\Users\HP\PycharmProjects\pythonProject\Python 试验.py", line 2, in <module> df = pd.read_csv('D:\\A过铁精矿\\ related.txt', header=None, skiprows=1, skipfooter=1, delimiter='\t') File "D:\ProgramData\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper return func(*args, **kwargs) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper return func(*args, **kwargs) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 950, in read_csv return _read(filepath_or_buffer, kwds) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 605, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 1442, in __init__ self._engine = self._make_engine(f, self.engine) File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\parsers\readers.py", line 1735, in _make_engine self.handles = get_handle( File "D:\ProgramData\anaconda3\lib\site-packages\pandas\io\common.py", line 856, in get_handle handle = open( FileNotFoundError: [Errno 2] No such file or directory: 'D:\\A过铁精矿\\ related.txt'
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值