【发布时间】:2017-08-27 09:50:52
【问题描述】:
我创建了一个代码来帮助我从 csv 文件中检索数据
import re
keywords = {"metal", "energy", "team", "sheet", "solar" "financial", "transportation", "electrical", "scientists",
"electronic", "workers"} # all your keywords
keyre=re.compile("energy",re.IGNORECASE)
with open("2006-data-8-8-2016.csv") as infile:
with open("new_data.csv", "w") as outfile:
outfile.write(infile.readline()) # Save the header
for line in infile:
if len(keyre.findall(line))>0:
outfile.write(line)
我需要它在 "position" 和 "Job description" 两个主要列中查找每个关键字,然后取出包含这些单词的整行并将它们写入新文件中。关于如何以最简单的方式完成此操作的任何想法?
【问题讨论】:
-
我需要它来查看所有关键字,例如它应该在“职位”和“职位描述”下查找包含“金属”字的行,并提取整行并将它们写入文件,然后查找第二个单词并执行相同操作直到最后一个单词
标签: python csv extract operator-keyword