这里有一个不同的方法......对于CSV文件时,Python包csvkit
安装了大量的命令 - 这些工具可让您轻松切割和切割.csv文件。
$ pip install csvkit
这将安装一个名为csvgrep
(等)的命令。
$ csvgrep -c 4 -r '\d{2}/03' yourfile.csv
First,Last,Address,Birthdate,Email
John,Smith,34 La La Lane,14/03/85,[email protected]
有一点要注意的是,csvkit
假定所有的.csv文件有标题行。这就是为什么csvgrep
的结果显示标题行。这也意味着,你将有一个头添加到你这样的数据文件:
First,Last,Address,Birthdate,Email
John,Smith,34 La La Lane,14/03/85,[email protected]
Sarah,Second,42 Wallaby Way,11/06/92,[email protected]
Third,Example,99 Peacock Terrace,04/12/89,[email protected]
命令行参数的说明:
$ csvgrep -c 4 -r '\d{2}/03' yourfile.csv
-c specifies which column you want to search
-r specifies the regular expression you want to match in the column
正则表达式“^ \ d {2}/03 '将匹配以2位开头的字符串,然后是'/',然后是'03'月份。
查看csvkit tutorial了解更多信息。
请编辑您的帖子以包含您的解决方案。谢谢。 – bernie 2013-02-26 23:26:35