Transpose columns to rows in Python data frame

Asked

Viewed 211 times

0

Good evening Stack colleagues. First I want to thank you for the help that this vcs provide. I come please ask for more help. According to the image below, I would like to transpose all data referring to the same date in a single line. Ex. inserir a descrição da imagem aqui

Thanks for the help

1 answer

1


whereas df is your Dataframe:

temp = df.groupby('data').cumcount() + 1

df = df.set_index(['data', temp]).unstack().sort_index(1, level=1) 

df.columns = ['_'.join(map(str,i)) for i in df.columns]  
  • 1

    Hi Leonardo, it was perfect. Thank you very much.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.