pandas resample and count if

313 views
Skip to first unread message

questions anon

unread,
Dec 16, 2015, 4:43:18 PM12/16/15
to pyd...@googlegroups.com
I would like to resample a daily dataset to yearly (jul-jun) and count occurrences if the value of the data is greater than a given value. 

a sample of the time series:

TEMPdailymax.head()
Out[102]: 
localtime
1972-01-20     20.80236
1972-01-21    19.40630
1972-01-22     18.22212
1972-01-23     22.93016
1972-01-24     23.04736
Freq: D, Name: temp, dtype: float64

and I am thinking something like the following:

TEMPcount=(TEMPdailymax.resample('AS-JUN', how={TEMPdailymax.values > 20, 'count'}))

this approach doesn't work but any ideas would be greatly appreciated??



Stephan Hoyer

unread,
Dec 16, 2015, 5:00:16 PM12/16/15
to pyd...@googlegroups.com
You can supply a custom function in the "how" argument. For example:

def my_count(series):
    return (series.values > 20).sum()

TEMPdailymax.resample('AS-JUN', how=my_count)

Cheers,
Stephan

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

questions anon

unread,
Dec 16, 2015, 5:09:41 PM12/16/15
to pyd...@googlegroups.com
perfect, thank you!
Reply all
Reply to author
Forward
0 new messages