I have aggregated data using pandas data frame. Below is some actual data shown and how I aggregated it.
fdf.groupby(['row',col'])['percent'].sum()
http://pastebin.com/R8XWpgtU
What I would like to do is create a 2d numpy array of this (rows = row, columns = col). Any slick way to do this ?
Another way I did something similar was create a pivot table
pivot_table(fdf,values='percent',rows='row',cols='col', aggfunc=np.sum)
In this case I want to convert this pivot table to 2d numpy array. Is there a way for me to index into each cell of this table. If so then I probably will be Ok with the table itself.
Try:
result = fdf.groupby(['row',col'])['percent'].sum()
result.unstack('col').values
Alternately:
fdf.pivot_table('percent', rows='row', cols='col', aggfunc='sum').values
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With