'How to re-organise this dataframe?

Many dataframe is concatenated to get a dataframe.The resulting dataframe look like follows

timestamp CC A0 B0 C0 CA CD  CC A1 B1 C1 CA CD  CC A2 B2 C2 CA CD
          10 <---values--->  <-----------no values ------------->
          15 <---values--->  <-----------no values ------------->
          16 <---values--->  <-----------no values ------------->
          18 <---values--->  <-----------no values ------------->
 values   <---no values--->  8 <---values--->   <---no values--->
          <---no values--->  9 <---values--->   <---no values--->
          <---no values--->  14<---values--->   <---no values--->
          <---no values--->  19<---values--->   <---no values--->
          <-----------no values ------------->   2 <---values--->
          <-----------no values ------------->   5 <---values--->
          <-----------no values ------------->   7 <---values--->
          <-----------no values ------------->   21<---values--->

CC A0 B0 C0 CA CD are part of dataframe 1, CC A1 B1 C1 CA CD are part of dataframe 2 and CC A2 B2 C2 CA CD are part of dataframe 3 before concatenation**

timestamp is the index of dataframe

I want to organise this data frame as below

timestamp CC A0 B0 C0   A1 B1 C1  A2 B2 C2 CA CD
          2   
          5 
          7 
          8 
 values   9
          10
          14
          15
          16
          18
          19
          21



Solution 1:[1]

The problem comes from the way you concatenated your dataframes. The argument axis=1 means that you want your concatenation happening on the columns, where here you want to have your rows being concatenated and your columns being merged. I suggest you simply use :

new_dataframe = pd.concat(list1).sort_index()

and it should concatenate your dataframes the way you want it and sort your values according to your indexes.

I'm not sure if CC is your index or not, but if you want to sort the dataframe according to the CC columns you can also apply:

new_dataframe = new_dataframe.sort_values("CC")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1