从csv文件中提取特定的列,并使用python将其复制到另一个 [英] to extract specific columns from a csv file and copy it to another using python
本文介绍了从csv文件中提取特定的列,并使用python将其复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个CSV文件,实际上是0和1的矩阵。我需要排除那些具有0的列,并只选择那些具有1的列,并将它们复制到另一个CSV文件。
I have a CSV file which is actually a matrix of 0's and 1's. I need to exclude those columns that have 0's and pick only those that have 1's and copy them to another CSV file.
这是我试过的:
reader=csv.DictReader(open("test1.csv","r"),[])
for data in reader:
if data==1:
print data
我做错了什么?
推荐答案
reader = csv.DictReader(open("test1.csv", "r"), [])
for data in reader:
if data[column header] != 0:
print data[column header]
这篇关于从csv文件中提取特定的列,并使用python将其复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文