2

All,

I have a list output as below and i would like to convert it to a DF.

attrb = [['nn', 'xx', 'yy'], ['aa', 'vv', 'bb'], ['cc', 'gg', 'hh'], ['jj', 'kk', 'uu'], ['ee', 'ww', 'qq'], ['tt', 'mm', 'ss'], ['tt', 'gg', 'll'], ['aa', 'qq', 'tt']]

as below

0    1    2  3   4   5   6   7  
nn   aa   cc jj  ee  tt  tt  aa     
xx   vv   gg  kk  ww  mm gg  qq
yy   bb   hh  uu  qq  ss  ll  tt

i have tried the below but this makes it a 3x8 matrix

 cf = pd.DataFrame(attrb)
 print(cf)
1
  • 2
    pd.DataFrame(attrb).T? Commented Jan 16, 2017 at 17:35

1 Answer 1

2

The simpliest is transpose by T:

df = pd.DataFrame(attrb).T
print (df)
    0   1   2   3   4   5   6   7
0  nn  aa  cc  jj  ee  tt  tt  aa
1  xx  vv  gg  kk  ww  mm  gg  qq
2  yy  bb  hh  uu  qq  ss  ll  tt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.