Q:

Activity log into Pandas Series

I have as input a csv with (USERID, Datetime)
In order to analyze the activity of my users I would like to generate a Pandas Series with the index being a date, and columns being my users (multiple series).
The values would be the sum of the activities of each user aggregated over that date (for instance: Day).
Thanks in advance.

A:

Fake data
n = 100
np.random.seed(1)
userid = np.random.randint(0, 10, n)
datetime = np.random.randint(0, 10, n) + pd.Timestamp('2016-1-1', freq='D')
activity = np.random.randint(0,1000, n)
df = pd.DataFrame({'USERID':userid, 'Datetime':datetime, 'activity':activity})
df.head(10)

    Datetime  USERID  activity
0 2016-01-10       5       788
1 2016-01-01       8        44
2 2016-01-03       9       271
3 2016-01-01       5       670
4 2016-01-08       0       475
5 2016-01-02       0       910
6 2016-01-08       1       499
7 2016-01-10       7       787
8 2016-01-09       6       251
9 2016-01-05       9       666

Solution
df.groupby(['Datetime', 'USERID'])['activity'].sum().unstack(fill_value=0)

USERID         0    1     2     3     4     5     6     7     8     9
Datetime                                                             
2016-01-01     0  166  1091  1878   583   670     0  1524   577   881
2016-01-02   910    0     0   810  2146   706   182   138  1157     0
2016-01-03     0    0     0     0   433     0  1955  1914   566   561
2016-01-04    51  407   598     0     0     0   440   783     0     0
2016-01-05     0  324   662     0     0     0     0   990    79  2849
2016-01-06     0  959     0   230   878     0     0   656   879   300
2016-01-07  1390  100     0   575     0     0     0   806    87  1243
2016-01-08   975  499   503     0   657     0   403   755     0  1271
2016-01-09   342    0   739   617     0  1297   251  1207   324   458
2016-01-10   963  832     0     0   975  1179     0   787   717   145

