Rahul Syal
Rahul Syal

Reputation: 625

Get only those string where specific ratio condition meets using diff tool SequenceMatcher

Any example where I can get two strings in a column of a dataframe when ratio condition met?

Example - While comparing one string with column of a dataframe, it should return only those when SequenceMatcher.ratio() > 0.8.

Upvotes: 1

Views: 64

Answers (1)

jezrael
jezrael

Reputation: 863611

IIUC use boolean indexing with filter by lambda function in Series.apply:

text = 'my text'
df1 = df[df['col'].apply(lambda x: SequenceMatcher(None, x, text).ratio()) > 0.8]

Upvotes: 1

Related Questions