how to unpivot dataframe pandas 1

how to unpivot dataframe pandas

df_unpivoted = df.melt(id_vars=['car_model'], var_name='date', value_name='0-60mph_in_seconds')
df_unpivoted

Here is what the above code is Doing:
1. We specify the column that we want to keep as the index of the dataframe.
2. We specify the column that we want to pivot as the column that we want to melt.
3. We specify the new column name for the column that we want to pivot.
4. We specify the new column name for the column that contains the values from the column that we want to pivot.

Similar Posts