I have a big dataframe with columns like this:
data = [
[0,'His score is 15/30',15,30],
[1, 'She scored 34/50 in math', np.NaN, np.NaN],
[2,'avg score is 32.5/50 for english',32,50],
[3,'He scored last @ 15/50',25,50]
]
df = pd.DataFrame(data, columns=['id','text','num','denom'])
| id | text | num | denom |
|-----:|:---------------------------------|------:|--------:|
| 0 | His score is 15/30 | 15 | 30 |
| 1 | She scored 34/50 in math | nan | nan |
| 2 | avg score is 32.5/50 for english | 32 | 50 |
| 3 | He scored last @ 15/50 | 25 | 50 |
I want to select all rows where df.num + '/' + df.denom in df.text
I tried the following code but it returns an empty DataFrame:
df.loc[df.apply(lambda row: (str(row.num)+'/' + str(row.denom)) in row.text, axis=1) ]