title: Pandas Groupby: Aggregate and Conditional
body: <p>I am grouping by item-date pairs in a PD dataframe and would like to add some custom conditional functions using lambda to a larger aggregation function. </p>
  
  <p>Using the tip <a href="https://stackoverflow.com/questions/40710811/count-items-greater-than-a-value-in-pandas-groupby">here</a>, I can do the following, which works properly and counts positive and negative values in the given column. </p>
  
  <pre><code>item_day_count=item_day_group['PriceDiff_pct'].agg({'Pos':lambda val: (val &gt; 0).sum(),'Neg':lambda val: (val &lt;= 0).sum()}).reset_index()
  </code></pre>
  
  <p>And I can also do a different aggregate that contains both pre-built aggregations and a custom percentile function that returns proper stats:</p>
  
  <pre><code>item_day_count_v2=item_day_group['PriceDiff_pct'].agg(['count','min',percentile(25),'mean','median',percentile(75),'max']).reset_index()
  </code></pre>
  
  <p>But I cannot figure out how to combine these into one larger function - I get the error : <code>AttributeError: 'DataFrameGroupBy' object has no attribute 'name'</code> when I try the below:</p>
  
  <pre><code>item_day_count_v3=item_day_group['PriceDiff_pct'].agg(['count',{'Pos_Return':lambda val: (val &gt; 0).sum(),'Neg_Return':lambda val: (val &lt;= 0).sum()},'min',percentile(25),'mean','median',percentile(75),'max']).reset_index() 
  </code></pre>
  
  <p>Does anyone know how to combine these functions? Seems like it I am close considering both work separately. Thanks for your help!</p>