I have a df
import pandas as pd
df= pd.DataFrame({'ID': [1,2,3],
'Text':['This num dogs and cats is (111)888-8780 and other',
'dont block cow 23 here',
'cat two num: dog and cows here'],
'Match':[[('cats', 86), ('dogs', 86), ('dogs', 29)],
[('cow', 33), ('dont', 57), ('cow', 100)],
[('cat', 100), ('dog', 100), ('cows', 86)] ]
})
And it looks like this
ID Text Match
0 1 This num dogs and cats is (111)888-8780 and other [(cats, 86), (dogs, 86), (dogs, 29)]
1 2 dont block cow 23 here [(cow, 33), (dont, 57), (cow, 100)]
2 3 cat two num: dog and cows here [(cat, 100), (dog, 100), (cows, 86)]
My goal is to create a function that only keeps certain item within Match column that are above a certain threshold (e.g. 80) so I tried the following
def threshold(column):
column_tup = column
keep_tuple = []
for col in column_tup:
if column_tup > 80:
keep_tuple.append()
return pd.Series([keep_tuple], index = ['Keep_Words'])
df_thresh = df.join(df.apply(lambda x: threshold(x), axis = 1))
But this gives me an error
'>' not supported between instances of 'str' and 'int'
My goal is to get a df with a new column Keep_Words that looks like the following where only score above 85 are kept in Keep_Words
ID Text Match Keep_Words
0 1 data data [(cats, 86), (dogs, 86)]
1 2 data data [(cow, 100)]
2 3 data data [(cat, 100), (dog, 100)]
How do I alter my code to reach my goal?