How to convert columns to row using pandas

Question:

How to convert rows as columns for a grouped output for a data.

Input (Agent and order_date_week are the index):

                       Average_Rating_Per_Week
Agent order_date_week                         
Abi   26                                   4.5
      27                                   5
      28                                   3.8
      29                                   4.0
      30                                   3.9

Output should be like this:

Agent  26    27   28    29    30 
Abi    4.5   5    3.8   4.0   3.9

like this I have 60 agents

Asked By: NarenCR

||

Answers:

You need to select the column and unstack:

df9['Average_Rating_Per_Week'].unstack('order_date_week')
Answered By: mozway
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.