Bruhlickd
Bruhlickd

Reputation: 73

Transpose column/row, change column name and reset index

I have a Pandas DF and I need to:

  1. Transpose my columns to rows,
  2. Transform these rows to indexes,
  3. Set the actual columns as titles for each columns (and not as part of rows) How can I do that?

Here is my DF before the transpostion:

enter image description here

Here is my Df after my failed transposition: enter image description here

Upvotes: 0

Views: 764

Answers (1)

Yash Laddha
Yash Laddha

Reputation: 152

After transposing, use:

df.columns = df.iloc[0]

to set column headers to the first row.

Then use the 'set_axis()' function to set indices for your rows. An explanation for this function is linked here

Upvotes: 1

Related Questions