环境:
Python 3.6.0 |Anaconda 4.3.1 (32-bit)| (default, Dec 23 2016, 12:06:52) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
详细内容见:https://docs.python.org/3.6/library/csv.html
首先根据
import csv
with open('a.csv',newline='') as csvfile:
spamreader = csv.reader(csvfile,delimiter=' ',quotechar='|')
for row in spamreader:
print (','.join(row))
在cmd运行后:
运行后会提示错误:
FileNotFoundError: [Errno 2] No such file or directory: 'a.csv'
网上找了下原因:
You are using a relative path, which means that the program looks for the file in the working directory. T
Python读取CSV文件的注意事项与解决方法

本文介绍了在Python 3.6环境中遇到的读取CSV文件的问题及解决方案。首先,由于使用了相对路径导致FileNotFoundError,通过确定Python的工作目录解决了此问题。接着,遇到UnicodeDecodeError,原因是CSV文件包含gbk编码无法识别的字符。通过将CSV文件转为UTF-8编码成功读取。最后,文章提到了时间戳转换为时间的操作。
最低0.47元/天 解锁文章
4万+

被折叠的 条评论
为什么被折叠?



