How to apply a quantile to a group_ws object?

I have a pandas groupby object called grouped . I can get grouped.mean() and other simple functions to work, but I cannot get grouped.quantile() to work. When I try to run grouped.quantile() I get the following error:

 ValueError: ('invalid literal for float(): groupA', u'occurred at index groups') 

I am grouping text labels, so I'm not sure why the function is trying to convert it to float. This should be a quantile calculation using floats in each group. Can someone help indicate what I'm doing wrong?

+4
source share
1 answer

It seems that quantile () is not ignoring the inconvenience columns and is trying to find quantiles for your text columns. Here's a trivial example:

 In [75]: df = DataFrame({'col1':['A','A','B','B'], 'col2':[1,2,3,4]}) In [76]: df Out[76]: col1 col2 0 A 1 1 A 2 2 B 3 3 B 4 In [77]: df.groupby('col1').quantile() ValueError: ('could not convert string to float: A', u'occurred at index col1') 

However, when I multiply only numeric columns, I get:

 In [78]: df.groupby('col1')['col2'].quantile() Out[78]: col1 A 1.5 B 3.5 
+3
source

All Articles