[英]Using a keyword need to return the entire sentence that contains and remove that from dataset using python pandas
我有一個數據集,我需要從 Review 列中找到一些特定的關鍵字,並且它需要從中返回整個評論。
例如,這句話是這樣的:非常好的產品交付。
我需要找到的關鍵字是nice並且我需要返回包含 nice 的整個句子,然后我需要從數據集中刪除返回的句子:
x = data.loc[data['Aspect'].str.match("product quality") & (data['Sentence'].str.contains("nice|good|great|best"))]
data.drop([x],inplace=True)
在 pandas 上怎么做?
您可以使用正則表達式來做到這一點。
pattern_to_remove = "(nice)|(good)|(great)|(best)"
row_filter = data['Sentence'].str.contains(patternDel) # a filter to determine if the row matches the pattern
data = data[~row_filter] # drop the rows
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.