【发布时间】:2014-04-01 02:09:32
【问题描述】:
我有一个包含日期的列 A 的 csv 文件。我想搜索日期并以数组(非常重要)格式返回相应的行。我将如何使用 python 做到这一点?谢谢。
excel文件:
A B C
1 12202014 403 302
2 12212014 312 674
3 12222014 193 310
输入:
Search csv file for 12212014
输出:
[12212014,312,674]
尝试代码:
date = '12212014'
with open('dates.csv', 'rt') as f:
reader = csv.reader(f, delimiter=',')
for row in reader:
if date == row[0]:
print "found the date"
如何返回行而不是仅返回打印语句?
【问题讨论】:
-
@PauloScardine 你好。我尝试查看它,但它没有告诉我如何在特定列中搜索并以数组格式返回整行