你可以做到這一點使用熊貓如下,如果你正在尋找含有關鍵字的列表中只有一個字行:
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)
我需要它來看待所有的關鍵字,例如,它應該尋找包括「金屬」字下的行「位置」和「工作描述」,然後提取整行並將它們寫入文件中,然後查找第二個單詞並執行相同操作直到最後一個單詞 –