Python3导入CSV文件的实例(跟Python2有些许的不同)
作者:舞扬Qaz 时间:2023-09-21 05:19:29
导入CSV文件导入数据的步骤
①打开xxx.csv文件
②首先读取文件头
③然后读取剩余头
④当发生错误时抛出异常
读取完所有内容后,打印文件头和剩余所有行
代码:
import csv
filename = 'enrollments.csv'
data = []
try:
with open(filename)as f:
reader = csv.reader(f)
header = next(reader)
data = [row for row in reader]
except:
pass
if header:
print(header)
print('=========================')#分隔行
for datarow in data:
print(datarow)
来源:https://blog.csdn.net/Qaz_wz/article/details/70172327
标签:Python3,导入,CSV
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
python实现吃苹果小游戏
2023-08-25 19:25:45
Python连接MySQL并使用fetchall()方法过滤特殊字符
2024-01-23 07:35:36
sqlserver巧用row_number和partition by分组取top数据
2024-01-28 12:33:39
js实现登录验证码
2023-09-06 05:43:27
七十六个网站用户体验要点
2010-08-11 14:52:00
mac下如何将python2.7改为python3
2023-12-07 17:14:43
![](https://img.aspxhome.com/file/2023/2/112822_0s.jpg)
SQLSERVER对索引的利用及非SARG运算符认识
2024-01-14 23:24:34
一步步解析Python斗牛游戏的概率
2021-05-03 05:17:27
使用PYTHON创建XML文档
2022-08-19 02:26:53
浅谈图表参数化设计
2010-08-29 18:03:00
![](https://img.aspxhome.com/file/UploadPic/20108/29/01-56s.jpg)
Python利用Django如何写restful api接口详解
2022-11-16 13:26:32
![](https://img.aspxhome.com/file/2023/0/98830_0s.jpg)
Python如何在循环内使用list.remove()
2023-06-07 09:11:33
vue.js 动态组件详解
2024-04-29 13:09:58
![](https://img.aspxhome.com/file/2023/0/132910_0s.png)
简单PHP上传图片、删除图片实现代码
2024-05-09 14:49:09
浅谈几种常用的JS类定义方法
2024-04-22 12:56:56
Python pandas库中的isnull()详解
2022-06-06 20:58:01
Python温度转换实例分析
2023-08-21 22:48:32
Python调用SQLPlus来操作和解析Oracle数据库的方法
2024-01-27 19:17:06
Python 用turtle实现用正方形画圆的例子
2022-08-05 13:56:33
![](https://img.aspxhome.com/file/2023/7/127857_0s.jpg)
python如何在pygame中设置字体并显示中文详解
2021-03-21 13:32:50