mercredi 29 septembre 2021

How to find a string match ( both partial and exact match) between column header and row values in python using if condition

id  references  apple  pomegranate
a234    papaya      0      1
b231    pomegranate 1      0
a234    apple       0      1
g34     mango       0      0
y34     strawberry  0      1

Is there a way to match column name "apple" with names in "references" column, so that I could extract the corresponding "id"....considering the data frame as say a distance value of two data frames about features of fruits.

The match is searched for exact string match in first iteration if it's not found, partial match also searched, say some "references" value may have a name "green apple". So it is partial match this case is considered when exact match is unavailable.

Aucun commentaire:

Enregistrer un commentaire