0

I have a table with only one row of data.

index A B C
0 20 30 50

I need to transpose it for presenting in a table:

Data Point Value
A 20
B 30
C 50

I've tried using df.transpose() but I end up with the index value as header for both columns:

0
A 20
B 30
C 50

Should I be trying to add a column or rename the index first? Any help would be appreciated.

  • 3
    You could call `reset_index()` after transpose and then rename the columns (By setting `df.columns` to `['Data Point', 'Value']` for example). Is that the output you're looking for? – 5eb Apr 01 '23 at 21:29
  • You're using Pandas, right? Please [edit] and add the tag for it. – wjandrea Apr 02 '23 at 00:17
  • BTW, welcome to Stack Overflow! Check out the [tour] and [ask] for tips like how to write a good title. See also [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea Apr 02 '23 at 00:28
  • @BasvanderLinden - that's done it perfectly thanks. – Ellen Regan Apr 02 '23 at 17:24

0 Answers0