Column Rename Regex

My column headers will change every time I run my analyses, as they are indexed to the time period of each piece of data, and I need to set up a Column Rename Regex to remove the first portion of each column title, even though it’s different each time.

I have my initial output, then complete a pivot to compare two different time periods side-by-side

In this case the “2023_2+First” will be different each time as it’s tied to the date of the data. This is the piece I need to remove/replace. The “Neighborhood AVG Close Price” remains the same each iteration.

I need to remove and replace the “2023_2+First” and the next time I run it “2023_3…”, and into eventually “2024_3…” etc.

So I want to set up a Regex to remove and replace anything that shows up in the column header before “Neighborhood AVG Close Price”.

Any suggestions are always appreciated!

Hi,
For this you can use \d{4}_\d{1,2}\+First(.+) as regex and $1 as the replacement. This will yield *(Neighborhood AVG Closing Price). If you also want to remove the * and the parentheses, you can use this regex instead: \d{4}_\d{1,2}\+First\*\((.+)\).
Kind regards,
Alexander

4 Likes

Hi @creedssmith, an alternative regex, if the column of interest is always (Neighborhood AVG Close Price … )

is to use the following Column Rename (Regex)

.*\((Neighborhood AVG Close Price.*)\)

again with $1 as the replacement

This assumes that it is surrounded by parentheses, and the parentheses are to be removed.

2 Likes

@AlexanderFillbrunn Wow, good thing I asked. I was not coming up with that on my own :slight_smile: :laughing: Thank You!

@takbb Thanks Brian, I appreciate the help always :grinning:

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.