0

I have a dataframe of 100+ columns and would like to turn each column into it's own dataframe with the same index of Date.

eg;

Original Dataframe;

Date     A B C D E F G H
01/01/12 3 8 9 2 9 3 3 2
02/01/12 7 8 7 7 3 2 0 3
.
.
.
.
31/01/19 8 2 9 3 2 7 2 0

End Goal;

Dataframe A;

Date     A
01/01/12 3
02/01/12 7
.
.
.
.
31/01/12 8

Dataframe B

Date     B
01/01/12 8
02/01/12 8
.
.
.
.
31/01/19 2

and so on for each other columns..

Any help much appreciated! Thanks

spcol
  • 437
  • 4
  • 15

1 Answers1

1

If want DataFrame called A,B,C by columns names is not recommended, better is create dictionary:

d = {c: df[[c]] for c in df.columns}
print (d)

print (d['A'])
          A
Date       
01/01/12  3
02/01/12  7
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Thanks jezrael! I want to use the groupby function afterwards so was hoping to be able to manipulate a dataframe. – spcol Aug 26 '20 at 08:36
  • 2
    @spcol - you get dictionary of DataFrames, so instead `df1, df2` use `d['A'], d['B']` and working same way. – jezrael Aug 26 '20 at 08:37