从csv中提取特定列

时间:2013-09-28 09:49:53

标签: python csv python-3.x

我有一个.csv文件,格式如下:

ID1    ID2    city       Country
AR     xyz    Tokyo      Japan
AR            New York   USA
AR     abc    Vienna     Austria

我想使用正则表达式从文件中提取第三列数据,因此输出将是:

Tokyo
New York
Vienna

1 个答案:

答案 0 :(得分:1)

为什么不使用csv模块?这可以快得多。

import csv

with open('this.file') as this_file:
  source = csv.reader(this_file, delimiter=' ')
  next(source)  # skipping header
  for row in source:
    print(row[3])
相关问题