title: performance issues with pandas apply
body: <p>I have the following dataframe df</p>
  <pre><code>                                   time       u10  ...        av  kont
  latitude  longitude                                ...                
  51.799999 -3.2      2011-01-07 09:00:00 -2.217477  ...  0.008106  None
            -3.1      2011-01-07 09:00:00 -2.137205  ...  0.008202  None
  51.900002 -3.1      2011-01-07 09:00:00 -2.276076  ...  0.008310  None
            -3.1      2011-01-07 10:00:00 -1.548405  ...  0.006344  None
            -3.0      2011-01-07 09:00:00 -2.200620  ...  0.008537  None
  52.200001 -3.9      2011-01-05 23:00:00  1.393586  ...  0.005413  None
            -3.8      2011-01-05 21:00:00  1.972752  ...  0.007624  None
            -3.8      2011-01-05 22:00:00  1.732336  ...  0.006696  None
            -3.8      2011-01-05 23:00:00  1.551723  ...  0.005837  None
            -3.8      2011-01-06 00:00:00  1.377130  ...  0.004979  None
            -3.7      2011-01-05 21:00:00  2.124066  ...  0.008008  None
            -3.7      2011-01-05 22:00:00  1.892480  ...  0.007125  None
            -3.7      2011-01-05 23:00:00  1.710662  ...  0.006296  None
            -3.6      2011-01-05 21:00:00  2.259727  ...  0.008230  None
            -3.6      2011-01-05 22:00:00  2.044596  ...  0.007428  None
            -3.6      2011-01-05 23:00:00  1.865990  ...  0.006652  None
  52.299999 -3.8      2011-01-05 23:00:00  1.652063  ...  0.006964  None
  </code></pre>
  <p>The entire dataframe can be downloaded from <a href="https://1drv.ms/u/s!Aj5DfuTWg1OMkNU2O4AMcaWwjdFF9g?e=Bi3jWm" rel="nofollow noreferrer">here</a>.</p>
  <p>I need to sum groups within <code>latitude</code>, <code>longitude</code> and <code>kont</code>. I am doing this with following function though apply:</p>
  <pre><code>        def summarize(group):
              s = group['kont'].eq('from').cumsum()
              return group.groupby(s).agg(
                  t2m=('t2m', 'mean'),
                  av=('av', 'sum'),
                  ah=('tp', 'sum'),
                  d1=('time', 'min'),
                  d2=('time', 'max')
              )
              
          df=df.groupby(['latitude', 'longitude']).apply(summarize).reset_index(level=-1, drop=True)
  </code></pre>
  <p>output is given <a href="https://1drv.ms/u/s!Aj5DfuTWg1OMkNU3EOtQI7hcl8uNrA?e=NIsHTd" rel="nofollow noreferrer">here</a>.
  However, I need to run this on a large dataframe and it takes hours to finish these operations, probably because of the use apply.
  Is there any pure pandas way of speeding this up? Is there any other way i.e. dask?</p>