Pandas and Time based data

import pandas as pd
import datetime as dt
import random
date_range=pd.date_range(start="1-Jan-2014 12:00",end="1-Jan-2015 12:00")
people=['bob','tom','frank','tim']
idx=0
data=[]
for d in date_range:
    r=int(random.random()*10%len(people))
    value=int(random.random()*100)
    print d,people[r],value
    rec=[d,people[r],value]
    data.append(rec)

r =[ a for a in range(365)]
r2 =[ a for a in range(365,0,-1)]
2014-01-01 12:00:00 bob 50
2014-01-02 12:00:00 frank 24
2014-01-03 12:00:00 tom 66
2014-01-04 12:00:00 tim 33
2014-01-05 12:00:00 tom 76
2014-01-06 12:00:00 frank 9
2014-01-07 12:00:00 bob 58
2014-01-08 12:00:00 tom 27
2014-01-09 12:00:00 bob 32
2014-01-10 12:00:00 bob 86
2014-01-11 12:00:00 frank 42
2014-01-12 12:00:00 tim 31
2014-01-13 12:00:00 tom 64
2014-01-14 12:00:00 tom 13
2014-01-15 12:00:00 tom 24
2014-01-16 12:00:00 tom 14
2014-01-17 12:00:00 frank 61
2014-01-18 12:00:00 bob 69
2014-01-19 12:00:00 bob 35
2014-01-20 12:00:00 tom 45
2014-01-21 12:00:00 tim 23
2014-01-22 12:00:00 bob 71
2014-01-23 12:00:00 tim 45
2014-01-24 12:00:00 bob 2
2014-01-25 12:00:00 frank 80
2014-01-26 12:00:00 frank 93
2014-01-27 12:00:00 tom 47
2014-01-28 12:00:00 tim 59
2014-01-29 12:00:00 bob 46
2014-01-30 12:00:00 tim 26
2014-01-31 12:00:00 frank 69
2014-02-01 12:00:00 bob 84
2014-02-02 12:00:00 tim 73
2014-02-03 12:00:00 tom 64
2014-02-04 12:00:00 tim 79
2014-02-05 12:00:00 tim 46
2014-02-06 12:00:00 tom 9
2014-02-07 12:00:00 bob 57
2014-02-08 12:00:00 tom 21
2014-02-09 12:00:00 bob 1
2014-02-10 12:00:00 frank 19
2014-02-11 12:00:00 frank 7
2014-02-12 12:00:00 bob 8
2014-02-13 12:00:00 tom 65
2014-02-14 12:00:00 bob 60
2014-02-15 12:00:00 bob 15
2014-02-16 12:00:00 tim 14
2014-02-17 12:00:00 bob 95
2014-02-18 12:00:00 bob 54
2014-02-19 12:00:00 tom 8
2014-02-20 12:00:00 tim 93
2014-02-21 12:00:00 bob 3
2014-02-22 12:00:00 bob 60
2014-02-23 12:00:00 tom 38
2014-02-24 12:00:00 tim 56
2014-02-25 12:00:00 bob 68
2014-02-26 12:00:00 tom 80
2014-02-27 12:00:00 tom 63
2014-02-28 12:00:00 tim 12
2014-03-01 12:00:00 tim 5
2014-03-02 12:00:00 tim 63
2014-03-03 12:00:00 bob 37
2014-03-04 12:00:00 bob 86
2014-03-05 12:00:00 bob 57
2014-03-06 12:00:00 tom 24
2014-03-07 12:00:00 tim 62
2014-03-08 12:00:00 frank 97
2014-03-09 12:00:00 bob 33
2014-03-10 12:00:00 tom 82
2014-03-11 12:00:00 tom 96
2014-03-12 12:00:00 tim 17
2014-03-13 12:00:00 frank 4
2014-03-14 12:00:00 tim 45
2014-03-15 12:00:00 tom 51
2014-03-16 12:00:00 tom 54
2014-03-17 12:00:00 tom 54
2014-03-18 12:00:00 tim 24
2014-03-19 12:00:00 frank 52
2014-03-20 12:00:00 frank 67
2014-03-21 12:00:00 frank 88
2014-03-22 12:00:00 bob 78
2014-03-23 12:00:00 tom 7
2014-03-24 12:00:00 bob 80
2014-03-25 12:00:00 tim 76
2014-03-26 12:00:00 frank 73
2014-03-27 12:00:00 frank 6
2014-03-28 12:00:00 bob 33
2014-03-29 12:00:00 bob 61
2014-03-30 12:00:00 bob 32
2014-03-31 12:00:00 bob 29
2014-04-01 12:00:00 tim 70
2014-04-02 12:00:00 tim 52
2014-04-03 12:00:00 tom 10
2014-04-04 12:00:00 tim 45
2014-04-05 12:00:00 tom 21
2014-04-06 12:00:00 bob 57
2014-04-07 12:00:00 bob 79
2014-04-08 12:00:00 tom 43
2014-04-09 12:00:00 tom 37
2014-04-10 12:00:00 frank 71
2014-04-11 12:00:00 tom 93
2014-04-12 12:00:00 bob 80
2014-04-13 12:00:00 tim 77
2014-04-14 12:00:00 bob 74
2014-04-15 12:00:00 bob 15
2014-04-16 12:00:00 bob 75
2014-04-17 12:00:00 tom 73
2014-04-18 12:00:00 tom 68
2014-04-19 12:00:00 tim 71
2014-04-20 12:00:00 bob 66
2014-04-21 12:00:00 tim 54
2014-04-22 12:00:00 tom 45
2014-04-23 12:00:00 tom 25
2014-04-24 12:00:00 tom 68
2014-04-25 12:00:00 tim 54
2014-04-26 12:00:00 tom 25
2014-04-27 12:00:00 bob 10
2014-04-28 12:00:00 tom 58
2014-04-29 12:00:00 tim 48
2014-04-30 12:00:00 frank 26
2014-05-01 12:00:00 bob 94
2014-05-02 12:00:00 frank 26
2014-05-03 12:00:00 bob 6
2014-05-04 12:00:00 tom 83
2014-05-05 12:00:00 tom 96
2014-05-06 12:00:00 tom 8
2014-05-07 12:00:00 bob 63
2014-05-08 12:00:00 frank 34
2014-05-09 12:00:00 frank 75
2014-05-10 12:00:00 tim 80
2014-05-11 12:00:00 tim 69
2014-05-12 12:00:00 tim 77
2014-05-13 12:00:00 tom 65
2014-05-14 12:00:00 frank 54
2014-05-15 12:00:00 tim 90
2014-05-16 12:00:00 tom 16
2014-05-17 12:00:00 bob 83
2014-05-18 12:00:00 tom 41
2014-05-19 12:00:00 tim 13
2014-05-20 12:00:00 tom 82
2014-05-21 12:00:00 bob 82
2014-05-22 12:00:00 tom 42
2014-05-23 12:00:00 tom 29
2014-05-24 12:00:00 frank 16
2014-05-25 12:00:00 bob 20
2014-05-26 12:00:00 bob 32
2014-05-27 12:00:00 bob 47
2014-05-28 12:00:00 tom 47
2014-05-29 12:00:00 tom 67
2014-05-30 12:00:00 tom 24
2014-05-31 12:00:00 frank 49
2014-06-01 12:00:00 frank 15
2014-06-02 12:00:00 tom 92
2014-06-03 12:00:00 bob 39
2014-06-04 12:00:00 tom 90
2014-06-05 12:00:00 tim 40
2014-06-06 12:00:00 bob 87
2014-06-07 12:00:00 frank 32
2014-06-08 12:00:00 tom 80
2014-06-09 12:00:00 bob 38
2014-06-10 12:00:00 frank 53
2014-06-11 12:00:00 tom 97
2014-06-12 12:00:00 tom 47
2014-06-13 12:00:00 bob 42
2014-06-14 12:00:00 tom 9
2014-06-15 12:00:00 tom 33
2014-06-16 12:00:00 frank 46
2014-06-17 12:00:00 tom 37
2014-06-18 12:00:00 bob 0
2014-06-19 12:00:00 bob 50
2014-06-20 12:00:00 bob 84
2014-06-21 12:00:00 frank 9
2014-06-22 12:00:00 frank 17
2014-06-23 12:00:00 tim 44
2014-06-24 12:00:00 tom 71
2014-06-25 12:00:00 tom 80
2014-06-26 12:00:00 tom 97
2014-06-27 12:00:00 tom 40
2014-06-28 12:00:00 tim 33
2014-06-29 12:00:00 tom 75
2014-06-30 12:00:00 tom 8
2014-07-01 12:00:00 tom 1
2014-07-02 12:00:00 bob 80
2014-07-03 12:00:00 bob 47
2014-07-04 12:00:00 tim 89
2014-07-05 12:00:00 tom 44
2014-07-06 12:00:00 tim 69
2014-07-07 12:00:00 tim 68
2014-07-08 12:00:00 bob 14
2014-07-09 12:00:00 bob 99
2014-07-10 12:00:00 tom 83
2014-07-11 12:00:00 bob 35
2014-07-12 12:00:00 bob 70
2014-07-13 12:00:00 tim 92
2014-07-14 12:00:00 tom 79
2014-07-15 12:00:00 tom 88
2014-07-16 12:00:00 bob 14
2014-07-17 12:00:00 tim 13
2014-07-18 12:00:00 bob 80
2014-07-19 12:00:00 tim 5
2014-07-20 12:00:00 tim 99
2014-07-21 12:00:00 tom 64
2014-07-22 12:00:00 tom 65
2014-07-23 12:00:00 bob 2
2014-07-24 12:00:00 tim 4
2014-07-25 12:00:00 bob 12
2014-07-26 12:00:00 bob 71
2014-07-27 12:00:00 frank 81
2014-07-28 12:00:00 tim 5
2014-07-29 12:00:00 tom 59
2014-07-30 12:00:00 frank 5
2014-07-31 12:00:00 frank 47
2014-08-01 12:00:00 tim 87
2014-08-02 12:00:00 bob 8
2014-08-03 12:00:00 bob 12
2014-08-04 12:00:00 tom 95
2014-08-05 12:00:00 frank 15
2014-08-06 12:00:00 tom 50
2014-08-07 12:00:00 frank 34
2014-08-08 12:00:00 bob 90
2014-08-09 12:00:00 frank 33
2014-08-10 12:00:00 tom 95
2014-08-11 12:00:00 tom 83
2014-08-12 12:00:00 tim 55
2014-08-13 12:00:00 frank 91
2014-08-14 12:00:00 bob 67
2014-08-15 12:00:00 bob 81
2014-08-16 12:00:00 frank 87
2014-08-17 12:00:00 bob 0
2014-08-18 12:00:00 tom 70
2014-08-19 12:00:00 frank 92
2014-08-20 12:00:00 bob 82
2014-08-21 12:00:00 tim 92
2014-08-22 12:00:00 tom 64
2014-08-23 12:00:00 frank 54
2014-08-24 12:00:00 tim 58
2014-08-25 12:00:00 tom 11
2014-08-26 12:00:00 bob 98
2014-08-27 12:00:00 tom 9
2014-08-28 12:00:00 frank 7
2014-08-29 12:00:00 tim 39
2014-08-30 12:00:00 tim 64
2014-08-31 12:00:00 frank 7
2014-09-01 12:00:00 bob 25
2014-09-02 12:00:00 bob 92
2014-09-03 12:00:00 frank 33
2014-09-04 12:00:00 tim 56
2014-09-05 12:00:00 tom 46
2014-09-06 12:00:00 frank 98
2014-09-07 12:00:00 tom 26
2014-09-08 12:00:00 frank 62
2014-09-09 12:00:00 frank 66
2014-09-10 12:00:00 bob 58
2014-09-11 12:00:00 bob 80
2014-09-12 12:00:00 tom 9
2014-09-13 12:00:00 tom 93
2014-09-14 12:00:00 tim 21
2014-09-15 12:00:00 bob 98
2014-09-16 12:00:00 frank 21
2014-09-17 12:00:00 tom 7
2014-09-18 12:00:00 tom 69
2014-09-19 12:00:00 tom 90
2014-09-20 12:00:00 frank 98
2014-09-21 12:00:00 tim 88
2014-09-22 12:00:00 tim 22
2014-09-23 12:00:00 frank 26
2014-09-24 12:00:00 frank 28
2014-09-25 12:00:00 bob 35
2014-09-26 12:00:00 tom 1
2014-09-27 12:00:00 tom 55
2014-09-28 12:00:00 bob 90
2014-09-29 12:00:00 frank 68
2014-09-30 12:00:00 tim 45
2014-10-01 12:00:00 tom 28
2014-10-02 12:00:00 tom 96
2014-10-03 12:00:00 tom 21
2014-10-04 12:00:00 tim 1
2014-10-05 12:00:00 frank 78
2014-10-06 12:00:00 tim 22
2014-10-07 12:00:00 bob 16
2014-10-08 12:00:00 tom 57
2014-10-09 12:00:00 tom 57
2014-10-10 12:00:00 tom 82
2014-10-11 12:00:00 bob 1
2014-10-12 12:00:00 tim 86
2014-10-13 12:00:00 tom 68
2014-10-14 12:00:00 bob 26
2014-10-15 12:00:00 tom 56
2014-10-16 12:00:00 bob 10
2014-10-17 12:00:00 tim 29
2014-10-18 12:00:00 tom 64
2014-10-19 12:00:00 tim 0
2014-10-20 12:00:00 tom 88
2014-10-21 12:00:00 bob 48
2014-10-22 12:00:00 tom 30
2014-10-23 12:00:00 bob 75
2014-10-24 12:00:00 tom 84
2014-10-25 12:00:00 tom 95
2014-10-26 12:00:00 tom 6
2014-10-27 12:00:00 tom 5
2014-10-28 12:00:00 tom 32
2014-10-29 12:00:00 frank 37
2014-10-30 12:00:00 bob 13
2014-10-31 12:00:00 bob 47
2014-11-01 12:00:00 tom 33
2014-11-02 12:00:00 bob 90
2014-11-03 12:00:00 tom 92
2014-11-04 12:00:00 bob 5
2014-11-05 12:00:00 bob 79
2014-11-06 12:00:00 tom 12
2014-11-07 12:00:00 frank 31
2014-11-08 12:00:00 bob 35
2014-11-09 12:00:00 tom 59
2014-11-10 12:00:00 tom 88
2014-11-11 12:00:00 bob 50
2014-11-12 12:00:00 bob 3
2014-11-13 12:00:00 bob 55
2014-11-14 12:00:00 frank 20
2014-11-15 12:00:00 tom 91
2014-11-16 12:00:00 bob 6
2014-11-17 12:00:00 tom 22
2014-11-18 12:00:00 bob 57
2014-11-19 12:00:00 tom 63
2014-11-20 12:00:00 frank 20
2014-11-21 12:00:00 tim 9
2014-11-22 12:00:00 bob 72
2014-11-23 12:00:00 bob 87
2014-11-24 12:00:00 tom 65
2014-11-25 12:00:00 tim 92
2014-11-26 12:00:00 bob 73
2014-11-27 12:00:00 tom 38
2014-11-28 12:00:00 tom 61
2014-11-29 12:00:00 bob 88
2014-11-30 12:00:00 tom 61
2014-12-01 12:00:00 tom 69
2014-12-02 12:00:00 bob 24
2014-12-03 12:00:00 tom 46
2014-12-04 12:00:00 tom 71
2014-12-05 12:00:00 frank 41
2014-12-06 12:00:00 bob 49
2014-12-07 12:00:00 tom 34
2014-12-08 12:00:00 tom 36
2014-12-09 12:00:00 frank 69
2014-12-10 12:00:00 bob 6
2014-12-11 12:00:00 bob 61
2014-12-12 12:00:00 tom 2
2014-12-13 12:00:00 bob 39
2014-12-14 12:00:00 frank 52
2014-12-15 12:00:00 bob 54
2014-12-16 12:00:00 bob 89
2014-12-17 12:00:00 frank 33
2014-12-18 12:00:00 bob 41
2014-12-19 12:00:00 frank 24
2014-12-20 12:00:00 tom 8
2014-12-21 12:00:00 bob 49
2014-12-22 12:00:00 tom 51
2014-12-23 12:00:00 tom 41
2014-12-24 12:00:00 bob 87
2014-12-25 12:00:00 tom 55
2014-12-26 12:00:00 bob 18
2014-12-27 12:00:00 tom 88
2014-12-28 12:00:00 bob 8
2014-12-29 12:00:00 frank 20
2014-12-30 12:00:00 bob 51
2014-12-31 12:00:00 bob 95
2015-01-01 12:00:00 bob 1
[[Timestamp('2014-12-23 12:00:00', offset='D'), 'tom', 41],
 [Timestamp('2014-12-24 12:00:00', offset='D'), 'bob', 87],
 [Timestamp('2014-12-25 12:00:00', offset='D'), 'tom', 55],
 [Timestamp('2014-12-26 12:00:00', offset='D'), 'bob', 18],
 [Timestamp('2014-12-27 12:00:00', offset='D'), 'tom', 88],
 [Timestamp('2014-12-28 12:00:00', offset='D'), 'bob', 8],
 [Timestamp('2014-12-29 12:00:00', offset='D'), 'frank', 20],
 [Timestamp('2014-12-30 12:00:00', offset='D'), 'bob', 51],
 [Timestamp('2014-12-31 12:00:00', offset='D'), 'bob', 95],
 [Timestamp('2015-01-01 12:00:00', offset='D'), 'bob', 1]]
df = pd.DataFrame(data,columns=['period','word','freq'])
df.tail()

#df = pd.DataFrame({'r': r, 'r2':r2},index=pd.date_range('20130101',periods=365)

top_user = df.groupby('word').freq.sum()
top_user.head()
period word freq
361 2014-12-28 12:00:00 bob 8
362 2014-12-29 12:00:00 frank 20
363 2014-12-30 12:00:00 bob 51
364 2014-12-31 12:00:00 bob 95
365 2015-01-01 12:00:00 bob 1
top_user.sort(['word'],ascending=False)
top_user[:2]
word
tom     6525
bob     5751
Name: freq, dtype: int64
df.groupby(['period','word']).sum().head(10)
freq
period word
2014-01-01 12:00:00 bob 50
2014-01-02 12:00:00 frank 24
2014-01-03 12:00:00 tom 66
2014-01-04 12:00:00 tim 33
2014-01-05 12:00:00 tom 76
2014-01-06 12:00:00 frank 9
2014-01-07 12:00:00 bob 58
2014-01-08 12:00:00 tom 27
2014-01-09 12:00:00 bob 32
2014-01-10 12:00:00 bob 86
df['period'] = df['period'].astype('datetime64[ns]')
df.head()
period word freq
0 2014-01-01 12:00:00 bob 50
1 2014-01-02 12:00:00 frank 24
2 2014-01-03 12:00:00 tom 66
3 2014-01-04 12:00:00 tim 33
4 2014-01-05 12:00:00 tom 76