I have one dataset I need to find some certain keywords from the Review column and it needs to return the entire review from it.
For example, the sentence is like this: very nice product delivered.
The keyword I need to find is nice and also I need to return the entire sentence that contains nice after that I need to remove the returned sentence from the dataset:
x = data.loc[data['Aspect'].str.match("product quality") & (data['Sentence'].str.contains("nice|good|great|best"))]
data.drop([x],inplace=True)
How do it on pandas?
You can use regex to do that.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.