Python中 CSV格式清洗与转换的实例代码
作者:Sound_of_ Silence 时间:2023-02-19 02:23:57
题目:
CSV格式清洗与转换
描述
附件是一个CSV格式文件,提取数据进行如下格式转换:
(1)按行进行倒序排列;
(2)每行数据倒序排列;
(3)使用分号(;)代替逗号(,)分割数据,无空格;
按照上述要求转换后将数据输出。
#!/usr/bin/python 3
# -*- coding: UTF-8 -*-
_Author_ = 'Sound_of_ Silence'
f = open('data.csv','r')
lines = f.readlines()
lines.reverse()
for line in lines:
line = line.replace('\n','')
line =line.replace(' ','')
t = line.split(",")
t.reverse()
print(";".join(t))
总结
以上所述是小编给大家介绍的Python中 CSV格式清洗与转换的实例代码,网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
来源:https://blog.csdn.net/weixin_44521703/article/details/91128714
标签:python,CSV,格式,转换
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
举例讲解Python装饰器
2022-02-17 10:49:18
批标准化层 tf.keras.layers.Batchnormalization()解析
2023-06-18 23:35:17
Python Playwright 文本框操作技巧
2023-01-15 20:59:21
![](https://img.aspxhome.com/file/2023/2/67882_0s.png)
SQL Server 2005 更改安装路径目录的方法小结
2024-01-25 12:15:45
![](https://img.aspxhome.com/file/2023/8/104128_0s.gif)
pytorch 实现模型不同层设置不同的学习率方式
2023-11-20 00:29:25
【推荐】汉字转为拼音的asp函数
2007-08-17 11:11:00
![](https://img.aspxhome.com/file/UploadPic/20078/17/2007817111835759s.jpg)
asp添加数据实现代码
2011-02-05 10:42:00
Python tornado上传文件的功能
2022-06-01 19:33:37
python多线程http压力测试脚本
2022-12-31 16:48:37
Python如何使用OS模块调用cmd
2023-03-22 02:25:39
vue源码之批量异步更新策略的深入解析
2024-05-09 15:21:30
![](https://img.aspxhome.com/file/2023/2/126442_0s.png)
vue之prop与$emit的用法说明
2024-05-09 15:20:41
python字典添加值的方法及实例代码分享
2023-04-22 09:58:13
Centos7下mysql 8.0.15 安装配置图文教程
2024-01-20 03:15:56
![](https://img.aspxhome.com/file/2023/0/66610_0s.png)
Sql Server 字符串聚合函数
2024-01-17 08:15:34
Flask和pyecharts实现动态数据可视化
2022-06-15 04:21:20
![](https://img.aspxhome.com/file/2023/3/100823_0s.png)
vue学习笔记之动态组件和v-once指令简单示例
2024-01-01 07:50:52
![](https://img.aspxhome.com/file/2023/5/82745_0s.png)
浏览器tab的设计
2008-08-11 13:03:00
![](https://img.aspxhome.com/file/UploadPic/20088/11/200881113621228s.jpg)
一次性压缩Sqlserver2005中所有库日志的存储过程
2012-01-29 17:58:28
使用游标进行PHP SQLSRV查询的方法与注意事项
2023-05-22 10:51:10