Python读取csv文件实例解析
作者:MilesMa 时间:2023-01-21 07:47:32
这篇文章主要介绍了Python读取csv文件实例解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
创建一个csv文件,命名为data.csv,文本内容如下:
root,123456,login successfully
root,wrong,wrong password
wrong,123456,nonexistent username
,123456,username is null
root,,password is null
使用Excel打开如图:
利用Python内置的csv读取内容:
import csv
with open('data.csv', 'r', encoding='utf-8')as f:
reader = csv.reader(f)
for i in reader:
print(i)
输出结果:
['root', '123456', 'login successfully']
['root', 'wrong', 'wrong password']
['wrong', '123456', 'nonexistent username']
['', '123456', 'username is null']
['root', '', 'password is null']
来源:https://www.cnblogs.com/milesma/p/12111751.html
标签:Python,读取,csv
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
如何在社区建立一个寻呼台?
2009-11-08 18:59:00
数据清洗之如何用一行Python代码去掉文本中的各种符号
2023-10-04 12:39:25
PHP遍历目录实现方法介绍
2023-05-25 06:31:41
php中json_encode不兼容JSON_UNESCAPED_UNICODE的解决方案
2023-09-27 17:22:32
Golang加密解密之RSA(附带php)
2024-05-08 10:21:28
如何使用Python 抓取和优化所有网站图像
2022-05-18 12:36:00
![](https://img.aspxhome.com/file/2023/0/77660_0s.png)
Python FTP操作类代码分享
2022-09-07 17:59:23
python实现生命游戏的示例代码(Game of Life)
2023-11-02 21:33:35
IE的有条件注释详解(附实例代码)
2009-03-31 13:01:00
![](https://img.aspxhome.com/file/UploadPic/20093/31/iecondition01-64s.gif)
比较规范的验证Email地址是否正确的正则表达式
2009-07-28 17:55:00
Python 忽略文件名编码的方法
2021-06-11 15:16:55
利用Python多线程实现图片下载器
2022-02-12 06:07:41
![](https://img.aspxhome.com/file/2023/5/131125_0s.jpg)
Python文本统计功能之西游记用字统计操作示例
2023-08-10 00:12:59
![](https://img.aspxhome.com/file/2023/2/131342_0s.png)
Python使用time模块实现指定时间触发器示例
2022-05-13 02:57:59
![](https://img.aspxhome.com/file/2023/0/82760_0s.png)
如何利用Pandas删除某列指定值所在的行
2023-10-29 11:49:39
![](https://img.aspxhome.com/file/2023/2/109392_0s.png)
PHP CURL CURLOPT参数说明(curl_setopt)
2023-11-14 19:06:44
详解IDEA git分支回退指定的历史版本
2022-01-25 16:03:55
![](https://img.aspxhome.com/file/2023/7/127197_0s.png)
Python开发装包八种方法详解
2021-01-12 22:27:28
python获取array中指定元素的示例
2021-09-11 15:37:43
xmlHttp msxml3.dll 错误 '800c0008' 解决办法
2008-08-31 20:44:00