I have a pandas dataframe where I have a a number of repeated column names that are preceded by some subcategory header. Here is an example: Dataframe with repeating headers.
What I would like to do, is to append the subcategory (e.g. Occupancy (%), ADR, RevPAR, etc.) to the repeated headers (This Year, Last Year, Percent Change). So that I achieve something of the sort:
"Occupancy (%): This Year, Occupancy (%): Last Year, ..., ADR: This Year, ADR: Last Year, ..."
I would also like to do this generally so that I am not explicitly specifying the header I'd like to append, but instructing to "return to the last non-repeating/non-duplicated header and append this to all following headers until the next non-repeating/non-duplicated header is reached and repeat"
Is this possible? Is there a simpler logic I could be using?