I am trying to group identical columns in a single dataframe, similar to this question: Grouping on identical column names in pandas
However that answer is not working for me. When I apply the accepted answer to that question, my dataframe has '.1' added to the second iteration of the duplicated columns. My duplicated columns do not have duplicated data, which may be the problem?
Here is my table:
Timepoint Col1 Col2 Col3 Col1 Col2 Col3
1 1 2 3
2 4 5 6
3 7 8 9
4 10 11 12
I would like the table to look like this:
Timepoint Col1 Col2 Col3
1 1 2 3
2 4 5 6
3 7 8 9
4 10 11 12
But the table looks like this when I apply the linked code:
Timepoint Col1 Col2 Col3 Col1.1 Col2.1 Col3.1
1 1 2 3
2 4 5 6
3 7 8 9
4 10 11 12
My dataframe has hundreds of columns so I need a solution that doesn't specify the columns that need to be grouped.
Note that this is not a duplicate of this question:Shift NaNs to the end of their respective rows because that question does not have duplicated column names and it shifts data to a differently labeled column.