In [4]:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib # only need to get matplotlib version
import sys # only need to get python version

In [5]:
print("Python version: " + sys.version)
print("Matplotlib version: " + matplotlib.__version__)
print("Numpy version: " + np.__version__)
print("Pandas version: " + pd.__version__)


Python version: 2.7.6 |Anaconda 1.9.2 (x86_64)| (default, Jan 10 2014, 11:23:15) 
[GCC 4.0.1 (Apple Inc. build 5493)]
Matplotlib version: 1.3.1
Numpy version: 1.8.0
Pandas version: 0.13.1

In [2]:
%matplotlib inline

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

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

In [24]:
alias = ['B', 'C', 'D', 'W', 'M', 'BM', 'MS', 'BMS', 'Q', 'BQ', 'QS', 'BQS', 'A', 'BA', 'AS', 'BAS', 'H', 'T', 'S', 'L', 'U']

In [28]:
description = ['business day frequency', 'custom business day frequency (experimental)', 'calendar day frequency', 
               'weekly frequency', 'month end frequency', 'business month end frequency', 'month start frequency', 
               'business month start frequency', 'quarter end frequency', 'business quarter end frequency', 
               'quarter start frequency', 'business quarter start frequency', 'year end frequency', 
               'business year end frequency', 'year start frequency', 'business year start frequency', 
               'hourly frequency', 'minutely frequency', 'secondly frequency', 'milliseconds', 'microseconds']

In [29]:
cheatsheet = pd.Series(description, index = alias)

In [30]:
print(cheatsheet)


B                            business day frequency
C      custom business day frequency (experimental)
D                            calendar day frequency
W                                  weekly frequency
M                               month end frequency
BM                     business month end frequency
MS                            month start frequency
BMS                  business month start frequency
Q                             quarter end frequency
BQ                   business quarter end frequency
QS                          quarter start frequency
BQS                business quarter start frequency
A                                year end frequency
BA                      business year end frequency
AS                             year start frequency
BAS                   business year start frequency
H                                  hourly frequency
T                                minutely frequency
S                                secondly frequency
L                                      milliseconds
U                                      microseconds
dtype: object

In [17]:
s


Out[17]:
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 [21]:
pd.date_range??

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 [ ]: