-1

I have a dataframe in pandas that consists of 600 columns and 8 rows. I want to produce a list that consists of column[0] (with its 8 rows) followed by column[1], then column[2].... column[600] in one big list. I tried to 'iterate' but cannot iterate with a loop (ie: for j in variablelist: biglist.append(variablelist[j]).

Although there is a solution here (Pandas: Multiple columns into one column) for combining two columns, I have a few hundred to combine.

Would appreciate any help.

Community
  • 1
  • 1
user1745691
  • 305
  • 2
  • 5
  • 12

1 Answers1

1

Use DataFrame.iteritems():

columns = [ series for colname, series in df.iteritems() ]
shx2
  • 61,779
  • 13
  • 130
  • 153
  • Thanks, but it doesn't work for my purposes. What that code does is that it reads off row 0 and turns it into a column. What I wanted was to change [[a, b, c], [d, e, f], [g, h, i]] -> [a,d,g, b, e, h, c, f, i] instead of [a,b,c,d,e,f,g,h,i] and using df.flatten(F) was the easiest way – user1745691 Nov 16 '15 at 10:02
  • @user1745691 first transpose your dataframe, then apply my solution: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.transpose.html – shx2 Dec 03 '15 at 06:40