I'm trying to convert daily temperature data to seasonal data, and can't figure out how to do it.

Assuming 0 knowledge of pandas for the OP, so apologies if this covers stuff you're already familiar with. First, to get a faux dataset we can work with:

import pandas as pd
import numpy as np
temp_data = pd.DataFrame({
    'X': np.arange(1, 12),
    'date': pd.date_range('2013-01-01', periods=2*365),
    'maxtp': np.random.rand(200, 800, 2*365)/10.,
})

This gives us a two-column frame with a general ascending integer index.

        date  maxtp
0 2013-01-01   40.8
1 2013-01-02   78.9
2 2013-01-03   60.5
3 2013-01-04   46.8
4 2013-01-05   36.2
5 2013-01-06   22.8
6 2013-01-07   54.9
7 2013-01-08   64.2
8 2013-01-09   38.6
9 2013-01-10   58.0

Now, pandas really shines when you index your data with timeseries, so let's re-index using the date range:

temp_data = temp_data.set_index('date')

which gives us:

            maxtp
date             
2013-01-01   40.8
2013-01-02   78.9
2013-01-03   60.5
2013-01-04   46.8
2013-01-05   36.2
2013-01-06   22.8
2013-01-07   54.9
2013-01-08   64.2
2013-01-09   38.6
2013-01-10   58.0

Sweet. We can easily group and aggregate this data in 3 month chunks by running:

g = pd.TimeGrouper('Q') // can also do "3m"
avg = temp_data.groupby(g).mean()

and we get:

                maxtp
date                 
2013-03-31  52.006667
2013-06-30  50.707692
2013-09-30  49.906522
2013-12-31  50.905435
2014-03-31  50.694444
2014-06-30  46.881319
2014-09-30  49.704348
2014-12-31  50.545652

But! OP wants daily values, not monthly or quarterly totals. My suggestion in this case is to add a column each for the month and year and why not, the day of the month as well.

temp_data['year'] = temp_data.index.year
temp_data['month'] = temp_data.index.month
temp_data['day'] = temp_data.index.day

temp_data = temp_data.set_index(['year', 'month', 'day'])

That last line gives us a multi-level index, which is super cool. So now we have:

                maxtp
year month day       
2013 1     1     40.8
           2     78.9
           3     60.5
           4     46.8
           5     36.2
           6     22.8
           7     54.9
           8     64.2
           9     38.6
           10    58.0

The output of this final command is a little too big, but run it and see the magic! :)

temp_data['maxtp'].unstack()
/r/Python Thread Parent