I have a DataFrame and I would like to perform a sorting if the match between my regex and the name of one of the lines of this DataFrame matches. Is there an option in the “re” library to help me? I try with this piece of code but without success Thank you in advance for your answers
JavaScript
x
12
12
1
regex = r"D.*cube"
2
3
for row in range(len(df)):
4
for col in range(len(df.columns)):
5
6
if df.iloc[row, col] == regex:
7
#treatment...
8
.
9
10
11
12
Advertisement
Answer
I think you probably want
JavaScript
1
10
10
1
pattern = r"D.*cube"
2
3
for row in range(len(df)):
4
for col in range(len(df.columns)):
5
6
if re.match(pattern, df.iloc[row, col]):
7
#treatment...
8
.
9
10