从csv文件读取每个列 [英] Reading each column from csv file
本文介绍了从csv文件读取每个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想读取csv文件的每一列并在将它们存储到表中之前进行一些修改。
I want to read each column of a csv file and do some modification before storing them into table.
我有一个csv文件:
"1";"testOne";"ValueOne"
"2";"testTwo";"ValueTwo"
"3";"testThree";"ValueThree"
这里我想读取第一个值1然后将它存储在一个变量,并做一些与这个值,并与其他人类似。但是目前我可以读取整个文件,但找不到连接一行的单独列的方法。
Here I want to read the first value "1" and then store it somewhere in a varaible and do something with this value, and similary with the others. However currently I can read the whole file, but could not find the way to access individual columns in a row.
谢谢。
推荐答案
Python有一个内置的 csv 模块。
Python has a built-in csv module.
import csv
with open('some.csv', 'rb') as f:
reader = csv.reader(f, delimiter=';')
for row in reader:
print row[0]
这篇关于从csv文件读取每个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文