Q: Python (pandas or other) - I need to "flatten" a data file from many rows, few columns to 1 row many columns

Viewed 132

I need to "flatten" a data file from many rows, few columns to 1 row many columns.

I currently have a dataframe in pandas (loaded from Excel) and ultimately need to change the way the data is displayed so I can accumulate large amounts of data in a logical manner. The below tables are an attempt at illustrating my requirements.

From:

         1      2
Ryan     0.706  0.071
Chad     0.151  0.831
Stephen  0.750  0.653

To:

1_Ryan  1_Chad  1_Stephen  2_Ryan  2_Chad  2_Stephen
0.706   0.151   0.75       0.071   0.831   0.653

Thank you for any assistance!

2 Answers
Related