python - Sublists in pandas -


i've got pandas dataframe, 1 of columns of looks this:

0              {u'funny': 2, u'useful': 0, u'cool': 0} 1        {u'funny': 370, u'useful': 487, u'cool': 296} 2             {u'funny': 2, u'useful': 17, u'cool': 1} 3     {u'funny': 1233, u'useful': 2452, u'cool': 1875} 4              {u'funny': 4, u'useful': 7, u'cool': 2} 5        {u'funny': 408, u'useful': 819, u'cool': 557} 6        {u'funny': 321, u'useful': 673, u'cool': 430} 7           nan 8              {u'funny': 0, u'useful': 8, u'cool': 0} 

i want break column out separate columns, without iterating on of rows explicitly (there lot, plus it's bad practice).

dataframe.thiscolumn[1]["funny"] returns 2, dataframe.thiscolumn[:]["funny"] doesn't work....

how can break separate columns?

thanks.

you apply series constructor column:

in [11]: df out[11]:                                                dics 0           {u'funny': 2, u'useful': 0, u'cool': 0} 1     {u'funny': 370, u'useful': 487, u'cool': 296} 2          {u'funny': 2, u'useful': 17, u'cool': 1} 3  {u'funny': 1233, u'useful': 2452, u'cool': 1875} 4           {u'funny': 4, u'useful': 7, u'cool': 2} 5     {u'funny': 408, u'useful': 819, u'cool': 557} 6     {u'funny': 321, u'useful': 673, u'cool': 430} 7           {u'funny': 0, u'useful': 8, u'cool': 0}  in [12]: df['dics'].apply(pd.series) out[12]:    cool  funny  useful 0     0      2       0 1   296    370     487 2     1      2      17 3  1875   1233    2452 4     2      4       7 5   557    408     819 6   430    321     673 7     0      0       8 

however, think it's best split these when constructing dataframe, rather once in dataframe.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -