首页 > 编程语言 > 详细

python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)

时间:2019-10-17 19:01:08      阅读:55      评论:0      收藏:0      [点我收藏+]

python 读取csv文件报错问题

import csv

with open(‘E:/Selenium2script/DDT模块/test.csv‘,‘rb‘) as f:
readers = csv.reader(f)
next(readers,None)
for line in readers:
print(line)

输出:
_csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)


问题分析:因为此csv文件是一个文本文件,并非二进制文件。

解决:

import csv

with open(‘E:/Selenium2script/DDT模块/test.csv‘,‘rt‘) as f:
readers = csv.reader(f)
next(readers,None)
for line in readers:
print(line)
或者‘rt’换成‘r’
————————————————
版权声明:本文为CSDN博主「海-最强的男人」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/c910118/article/details/78629153

python读取文件报错:pandas.errors.ParserError: iterator should return strings, not bytes (did you open the file in text mode?)

原文:https://www.cnblogs.com/houfei/p/11693835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!