I am checking to see if a pandas column matches a pre-defined regex, using .any() to get the first match if found. However, I need to return the index/row where this match occurred so that I can get the value of another column in that row.
I have the below to check where the reg_ex pattern exists in df['id_org']
if df['id_org'].str.contains(pat=reg_ex, regex=True).any()
Once the above evaluates to true, how do I get the index/row that caused the expression to evaluate to true? I would like to use this index so that I can access another column for that same row using pandas df.at[index, 'desired_col'] or .iloc functions.
In the past I have done: df.at[df['id_org'][df['id_org'] == key].index[0], 'desired_col'] however, I can't use this line of code any more because I am no longer checking for an exact string "key" match bur rather when a regex now matches in that column.