Let's say I have a pandas dataframe with string content in its cells.
What's the best way to find a string that matches an specific regex and then return a list of tuples with their respective row and column indexes?
I.e.,
import pandas as pd
mydf = pd.DataFrame({'a':['hello', 'world'], 'b': ['hello', 'folks']})
def findIndex(mydf, regex):
return regex_indexes
If I do:
regex = r"hello"
findIndex(mydf, regex) # it'd return [(0,0), (0,1)],
If I do:
regex = r"matt"
findIndex(mydf, regex) # it'd return [(-1,-1)],
If I do:
regex = r"folks"
findIndex(mydf, regex) # it'd return [(1,1)],
I could do a double for loop on the pd.DataFrame but was wondering if other ideas are better...
Nonebe better for no match?