1

I have to transpose my csv file datas using python:

Actual output:

sen 1.2
zen 2.2
ben 3.3

Expected output:

sen zen ben
1.2 2.2 3.3

I want to get sen, zen, and ben to be displayed horizontally in a straight row and the values under it

Andreas
  • 2,455
  • 10
  • 21
  • 24
Vani
  • 11
  • 2
  • 2
    Welcome to StackOverflow. Please take the time to read this post on how to provide a [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on [how to ask a good question](https://stackoverflow.com/help/how-to-ask) may also be useful. – Nihal Sangeeth Mar 25 '19 at 06:38
  • Mate what is the input of your data? Could you please divide it to rows and collumns if you want an answer. Otherwise The df.T answer takes the transpose of your input – Meric Ozcan Mar 25 '19 at 06:45
  • Possible duplicate of [how to switch columns rows in a pandas dataframe](https://stackoverflow.com/questions/31658183/how-to-switch-columns-rows-in-a-pandas-dataframe) – Sociopath Mar 25 '19 at 07:07
  • Mate do you know what are you doing? The actual output and expected output are transpose of each other already. – Meric Ozcan Mar 25 '19 at 07:38

2 Answers2

1

To transpose a dataframe:

df = df.T
Tabbakhh
  • 425
  • 3
  • 12
1

If data is in numpy matrix use

numpy.transpose(matrix)

If data is in Pandas use

df.T

For any other format you have to use loops

Refer the link [https://www.geeksforgeeks.org/transpose-matrix-single-line-python/][1]