Home > Software engineering >  create a unique row of dataframe by adding row by row
create a unique row of dataframe by adding row by row

Time:03-02

I have a question I have dataframe like a below picture:

enter image description here

I want to change it like this picture

enter image description here is there any pandas function to use for this aim?

CodePudding user response:

import pandas as pd
df = pd.DataFrame(data={'A': [100, 2000, 362], 
                        'B': [100, 2452, 362],
                        'C': [656, 4325, 3555]})
df = df.stack().reset_index().iloc[:,1:].set_index('level_1').T

>>> df
level_1    A    B    C     A     B     C    A    B     C
0        100  100  656  2000  2452  4325  362  362  3555 
  • Related