The dataframe must not have duplciates for each (index value, pivot column value) combination.
The pivot makes each index value a row, each pivot column's value a new column, and the column value from a thrid column.
The unpivot / melt is the opposite of pivot. The transforms the pivoted columns' names (specified in value vars) back into a single column as column values. The values are put back into a separate value column.
df = pd.DataFrame({'category': ['one', 'one', 'one', 'two', 'two',
'two'],
'column1': ['A', 'B', 'C', 'A', 'B', 'C'],
'column2': [1, 2, 3, 4, 5, 6]
})
df_pivot = df.pivot(index='category', columns=['column1'], values='column2')
df_pivot = df_pivot.reset_index()
df_melt = pd.melt(df_pivot, id_vars='category', value_vars=['A', 'B', 'C'], var_name = 'column a', value_name='column b')
df_melt