Home > Blockchain >  how to move column values to be titles in pandas
how to move column values to be titles in pandas

Time:04-11

I have been working on a project. my issue is I have repeated column values that I would like to have titles. but nothing seems to be working my work

so for perspective in the image. would like to have instead of 'outage type' , I would prefer to have a separate column for 'planned outage' 'forced outage', and 'emergency outage'

CodePudding user response:

Something like this?

import pandas as pd
import numpy as np

df = pd.DataFrame({"Asset Name": list('abcdefghijklmnopqr'),
                   "Outage Type": ["Forced","Planned","Urgent"]*6,
                   "tot_diff": np.random.randint(0, 3, 18),
                   "count": np.random.randint(0, 20, 18),
                   "seconds": np.random.randint(0, 1000, 18)})

df2 = df.pivot(index="Asset Name", columns="Outage Type")

df is the input, similar to your dataframe, and df2 is the output, with separate columns for the different Outage Type.

  • Related