Skip to content Skip to sidebar Skip to footer

Generate New Dataframe With Values In Old Dataframe As New Features In Python

I have a old data frame like: Name Courses Attendence Day Mike Math 1 Monday Mike Math 1 Tuesday Mike Physcis 2 Mon

Solution 1:

Use pd.pivot_table()

pivoted = pd.pivot_table(data=df, columns='Courses', index='Name',
                         aggfunc='sum', fill_value=0)

Let me know if you run into problems.

Post a Comment for "Generate New Dataframe With Values In Old Dataframe As New Features In Python"