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

4
  • 2
    Welcome to StackOverflow. Please take the time to read this post on how to provide a minimal, complete, and verifiable example and revise your question accordingly. These tips on how to ask a good question may also be useful. Commented Mar 25, 2019 at 6: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 Commented Mar 25, 2019 at 6:45
  • Possible duplicate of how to switch columns rows in a pandas dataframe Commented Mar 25, 2019 at 7:07
  • Mate do you know what are you doing? The actual output and expected output are transpose of each other already. Commented Mar 25, 2019 at 7:38

2 Answers 2

1

To transpose a dataframe:

df = df.T
Sign up to request clarification or add additional context in comments.

Comments

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]

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.