1#Import pandas module
2import pandas as pd
3
4# Define the dataframe
5DF = pd.DataFrame({'y': [1,4], 'female': [2,5], 'male': [3,6]})
6
7# Gather/melt the data frame
8pd.melt(DF, id_vars='y', value_vars=['female', 'male'],var_name='gender',
9value_name='value')
10