「Python」python读写csv文件并增加行列
来源:互联网 发布:scp基金会知乎 编辑:程序博客网 时间:2024/06/05 03:57
# -*- coding: utf-8 -*-"""Created on Thu Aug 17 11:28:17 2017@author: Shawn Yuen"""import csvd = list(range(38685))with open('./kinetics_test.csv') as f1: f_csv = csv.DictReader(f1) for i, row in enumerate(f_csv): #print(row) key1 = 'label' value1 = 'test' row[key1] = value1 key2 = 'is_cc' value2 = '0' row[key2] = value2 d[i] = rowf1.close()headers = ['label', 'youtube_id', 'time_start', 'time_end', 'split', 'is_cc']with open('./kinetics_test_new_.csv', 'w') as f: f_csv = csv.DictWriter(f, headers) f_csv.writeheader() f_csv.writerows(d)f.close()with open('./kinetics_test_new_.csv','rt') as fin: lines='' for line in fin: if line!='\n': lines+=linewith open('./kinetics_test_new.csv','wt')as fout: fout.write(lines)
为了下载test数据,方法一: 用Excel打开csv文件,手动添加label和is_cc; 方法二: 利用python里面的csv模块改写。生成的csv文件中奇怪的多了一些空行,然后找到解决方法,见参考资料。
python使用writerows写csv文件产生多余空行
python 定义给定初值或长度的list
阅读全文
0 0
- 「Python」python读写csv文件并增加行列
- Python读写csv文件
- python 读写 csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- Python读写csv文件
- python读写csv文件
- Python 读写CSV文件
- python 读写csv文件
- python 读写CSV 文件
- Python读写CSV文件
- python 读写csv文件
- 理解RESTful架构
- 静态绑定与动态绑定
- java web Maven 打包.sh .bat执行脚本
- config
- 为了保证页面输出安全,我们经常需要对一些特殊的字符进行转义,请写一个函数escapeHtml,将<, >, &, “进行转义
- 「Python」python读写csv文件并增加行列
- mui 上拉加载/下拉刷新异常 双滚动条异常
- C++11:强类型枚举
- echarts图表点击事件之跳转页面和加载页面
- 常用快捷键——Webstorm——IDEA
- git操作概述
- 基于要素(标题、父、类型、进程、控件id)获取windows窗口
- 构造器的调用顺序
- 序sort