Vani
Vani

Reputation: 11

How to transpose datas in csv file using python

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

Upvotes: 1

Views: 211

Answers (2)

aman nagariya
aman nagariya

Reputation: 172

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]

Upvotes: 1

Tabbakhh
Tabbakhh

Reputation: 460

To transpose a dataframe:

df = df.T

Upvotes: 1

Related Questions