Image containing the problem, click here
Please review the image
You can achieve this by using the function melt()
, which to massage a DataFrame into a format where one or more columns are identifier variables (here Campus
), while all other columns, considered measured variables (here Apr
, May,
June`), are "unpivoted" to the row axis as the following code snippet illustrates:
import pandas as pd
df1 = pd.DataFrame({'Campus': ['A', 'B'],
'Apr': [55, 1],
'May': [56, 2],
'June': [57, 3],
})
df2 = df1.melt(id_vars='Campus',var_name='Month',value_name='Value')
df2
has then the following content:
Campus Month Value
0 A Apr 55
1 B Apr 1
2 A May 56
3 B May 2
4 A June 57
5 B June 3