I have data frame with about 100 columns that repeat itself because the data is organized by weeks, it looks something like that:
| hours | hours | clicks | clicks | days | days | minutes | minutes |
|---|---|---|---|---|---|---|---|
| week 1 | week 2 | week 1 | week 2 | week 1 | week 2 | week 1 | week 2 |
| 2 | 2 | 2 | 3 | 6 | 2 | 2 | 3 |
| 1 | 7 | 6 | 3 | 8 | 2 | 9 | 3 |
I would like the output to look like this:
| hours_w1 | hours_w2 | clicks_w1 | clicks_w2 | days_w1 | days_w2 | minutes_w1 | minutes_w2 |
|---|---|---|---|---|---|---|---|
| 2 | 2 | 2 | 3 | 6 | 2 | 2 | 3 |
| 1 | 7 | 6 | 3 | 8 | 2 | 9 | 3 |
I know I can just rename the columns but because I have over 100 columns I'm looking for a more efficient way.
I tried to use add_suffix but had only managed to add the same suffix to all columns, when what I need is a different index for each week.
any idea how to do this?
Thanks!!
df.head().to_dict()for clarity, it's unclear whether you have a MultiIndex of data as header