I have got the following dataframe
df = pd.DataFrame({'ISIN': ['A', 'B', 'C'],
'Jan': [40000, 50000, 42000],
'Feb': [40000, 50000, 42000],
'Mar': [40000, 50000, 42000]})
Which produces
ISIN Jan Feb Mar
0 A 40000 50000 42000
1 B 40000 50000 42000
2 C 40000 50000 42000
I am trying to produce an output where the data looks like this:
Date A B C
0 Jan 40000 40000 40000
1 Feb 50000 50000 50000
2 Mar 42000 42000 42000
My first pass as this was to simply transpose the analysis using
df = df.T
That sort of worked except for the ISIN row (ie what I want as my column headers) were still sitting in the dataset:
0 1 2
ISIN A B C
Jan 40000 40000 40000
Feb 50000 50000 50000
Mar 42000 42000 42000
I then tried to pop out the ISIN row before doing the transpostion, ie
ISIN = df.pop('ISIN') df = df.T
That stripped out the ISIN row but then when I try to insert my popped column (using df.insert) and change the axis...I get stuck
I also tried using df.melt but I struggled to get the right things in the right places
I'm sure that this is very easy but I'm going around in circles here and I would really appreciate some wisdom.
Thanks!