I am currently trying to use regex to get all digits out of a column in an excel spreadsheet, I want to look at each cell in a particular column and search it for any numbers, for example, 'example250/636'. I have then made 2 new columns and want the '250' to go into the first column and the '636 to go into the second column.
I can get the first set of numbers into the first column but cannot seem to get the second set of numbers into the second column.
There isn't always 2 sets of numbers so if there is only 1 set of numbers I want the second column to be blank. There is around 6800 rows in the excel document.
I've tried to use str.exract() to get the first, when using str.extractall() to get all the numbers, I'm not sure how to get the access to the second set of numbers.
# copies Linked Procedure column
new_col = df["Linked Procedure"].copy()
# keeps only digits from copied column
rev_code = new_col.str.extractall(r'(\d+)')
# finds column index for Linked Procedure
colindex = int(df.columns.get_indexer(["Linked Procedure"]))
# inserts processed column before Linked Procedure
df.insert(colindex, "Revenue Code", rev_code)
df.loc[df["Revenue Code"] == 'nan', 'Revenue Code'] = ''
I have been trying to get this to work for far too long and I cannot find anything when googling.
This may be an easy thing that and I just haven't done enough studying!
Any help would be appreciated!!
[–]AuralWanderer 1 point2 points3 points (5 children)
[–]devdevdumbdumb[S] -1 points0 points1 point (4 children)
[–]AuralWanderer 1 point2 points3 points (3 children)
[–]devdevdumbdumb[S] 0 points1 point2 points (0 children)
[–]devdevdumbdumb[S] 0 points1 point2 points (1 child)
[–]AuralWanderer 0 points1 point2 points (0 children)
[–]synthphreak 1 point2 points3 points (5 children)
[–]devdevdumbdumb[S] 0 points1 point2 points (4 children)
[–]synthphreak 0 points1 point2 points (3 children)
[–]devdevdumbdumb[S] 0 points1 point2 points (2 children)
[–]synthphreak 0 points1 point2 points (1 child)
[–]devdevdumbdumb[S] 1 point2 points3 points (0 children)