rng = pd.date_range('1/1/2011', periods=72, freq='H')
np.random.seed(10)
n = 10
df = pd.DataFrame({'datetime': np.random.choice(rng, n), 'cat': np.random.
    choice(['a', 'b', 'b'], n), 'val': np.random.randint(0, 5, size=n)})
Group by year/month/day in pandas