你可以做到这一点使用熊猫如下,如果你正在寻找含有关键字的列表中只有一个字行:
keywords = ["metal", "energy", "team", "sheet", "solar" "financial", "transportation", "electrical", "scientists",
"electronic", "workers"]
# read the csv data into a dataframe
# change "," to the data separator in your csv file
df = pd.read_csv("2006-data-8-8-2016.csv", sep=",")
# filter the data: keep only the rows that contain one of the keywords
# in the position or the Job description columns
df = df[df["position"].isin(keywords) | df["Job description"].isin(keywords)]
# write the data back to a csv file
df.to_csv("new_data.csv",sep=",", index=False)
如果你正在寻找的行子(例如,在寻找financial engineering
financial
),那么你可以做到以下几点:
keywords = ["metal", "energy", "team", "sheet", "solar" "financial", "transportation", "electrical", "scientists",
"electronic", "workers"]
searched_keywords = '|'.join(keywords)
# read the csv data into a dataframe
# change "," to the data separator in your csv file
df = pd.read_csv("2006-data-8-8-2016.csv", sep=",")
# filter the data: keep only the rows that contain one of the keywords
# in the position or the Job description columns
df = df[df["position"].str.contains(searched_keywords) | df["Job description"].str.contains(searched_keywords)]
# write the data back to a csv file
df.to_csv("new_data.csv",sep=",", index=False)
我需要它来看待所有的关键字,例如,它应该寻找包括“金属”字下的行“位置”和“工作描述”,然后提取整行并将它们写入文件中,然后查找第二个单词并执行相同操作直到最后一个单词 –