In [1]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

In [2]:
%matplotlib inline

In [44]:
# this limit maximum numbers of rows displayed on screen
pd.set_option("display.max_rows", 15)

In [45]:
pd.__version__


Out[45]:
'0.13.1'

In [46]:
s = pd.Series([1,3,5,np.nan,6,8])

In [47]:
s


Out[47]:
0     1
1     3
2     5
3   NaN
4     6
5     8
dtype: float64

In [38]:
dates = pd.date_range('1950-01', '2013-03', freq='D')

In [39]:
dates


Out[39]:
<class 'pandas.tseries.index.DatetimeIndex'>
[1950-01-06, ..., 2013-03-06]
Length: 23071, Freq: D, Timezone: None

In [40]:
t = pd.Series(np.ones(dates.shape[0])*5, index=dates)

In [41]:
t_utc = t.tz_localize('UTC')

In [42]:
t_utc


Out[42]:
1950-01-06 00:00:00+00:00    5
1950-01-07 00:00:00+00:00    5
1950-01-08 00:00:00+00:00    5
...
2013-03-04 00:00:00+00:00    5
2013-03-05 00:00:00+00:00    5
2013-03-06 00:00:00+00:00    5
Freq: D, Length: 23071

In [43]:
t.resample('M', how='mean')


Out[43]:
1950-01-31    5
1950-02-28    5
1950-03-31    5
...
2013-01-31    5
2013-02-28    5
2013-03-31    5
Freq: M, Length: 759

In [30]:
t.resample('M', how='count')


Out[30]:
1950-01-31    26
1950-02-28    28
1950-03-31    31
1950-04-30    30
1950-05-31    31
1950-06-30    30
1950-07-31    31
1950-08-31    31
1950-09-30    30
1950-10-31    31
1950-11-30    30
1950-12-31    31
1951-01-31    31
1951-02-28    28
1951-03-31    31
...
2012-01-31    31
2012-02-29    29
2012-03-31    31
2012-04-30    30
2012-05-31    31
2012-06-30    30
2012-07-31    31
2012-08-31    31
2012-09-30    30
2012-10-31    31
2012-11-30    30
2012-12-31    31
2013-01-31    31
2013-02-28    28
2013-03-31     6
Length: 759

In [31]:
t.resample('M', how='sum')


Out[31]:
1950-01-31    130
1950-02-28    140
1950-03-31    155
1950-04-30    150
1950-05-31    155
1950-06-30    150
1950-07-31    155
1950-08-31    155
1950-09-30    150
1950-10-31    155
1950-11-30    150
1950-12-31    155
1951-01-31    155
1951-02-28    140
1951-03-31    155
...
2012-01-31    155
2012-02-29    145
2012-03-31    155
2012-04-30    150
2012-05-31    155
2012-06-30    150
2012-07-31    155
2012-08-31    155
2012-09-30    150
2012-10-31    155
2012-11-30    150
2012-12-31    155
2013-01-31    155
2013-02-28    140
2013-03-31     30
Freq: M, Length: 759

In [ ]: