Is there a pandas function to convert all the column heads against a particular header row into rows for that particular header

Viewed 40
1 Answers

You can use pd.melt() to convert your dataframe from a wide to a long format where 'CATEGORY' is your identifier variable, and elements under all of the other columns are values and get their own row.

new_df = df.melt(id_vars=['CATEGORY'], value_vars = ['ELCH_TOT','FXCH','FPA','ELDT','MTR_RENT','SOLAR_REBATE'])
Related