0
  Ad-Slot Id   Click Time                    Click IP
0   208878    2017-03-23 18:30:00.059   2405:204:c:3868:f27d:db2c:e2a9:c90c
1   195915  2017-03-23 18:30:00.107   2405:204:4183:6939:d3c2:bf40:ed47:3a6d
2   129192  2017-03-23 18:30:00.309   2405:204:900a:5700:cd84:2eec:449e:6af6
3   195987  2017-03-23 18:30:00.311   27.62.33.203
4   209078  2017-03-23 18:30:00.523   182.65.23.82
5   206706  2017-03-23 18:30:00.637   2405:205:1308:f499:b1d1:931a:2266:a738
6   210917  2017-03-23 18:30:01.136   42.106.17.94
7   236944  2017-03-23 18:30:01.226   171.61.19.146
8   195980  2017-03-23 18:30:01.331   2405:204:4088:1b4d::17ac:38ac

I have above data snippet and need to find out number of clicks per unit of time (1 minute, 5 minute, 1 hr) for each publisher (Ad-Slot Id).

Seema Mudgil
  • 365
  • 1
  • 7
  • 15

1 Answers1

0

Note: I modified your data snippet to have some multiple Ad-slot Id's per second, just for testing. So my output will be different from yours.

data snippet:

 Ad-Slot_Id   Click Time                    Click_IP
0   208878    2017-03-23 18:30:00.059   2405:204:c:3868:f27d:db2c:e2a9:c90c
1   236944  2017-03-23 18:30:00.107   2405:204:4183:6939:d3c2:bf40:ed47:3a6d
2   129192  2017-03-23 18:30:00.309   2405:204:900a:5700:cd84:2eec:449e:6af6
3   129192  2017-03-23 18:30:00.311   27.62.33.203
4   236944  2017-03-23 18:30:00.523   182.65.23.82
5   206706  2017-03-23 18:30:00.637   2405:205:1308:f499:b1d1:931a:2266:a738
6   129192  2017-03-23 18:30:01.136   42.106.17.94
7   236944  2017-03-23 18:30:01.226   171.61.19.146
8   129192  2017-03-23 18:30:01.331   2405:204:4088:1b4d::17ac:38ac

I am grouping the DataFrame by Ad-Slot Id, then resampling per second/minute/whatever you want, and counting the number of objects:

df = pd.read_clipboard()
df.index = pd.to_datetime(df['Click'] + ' ' + df['Time'])
resampletime = 's'
for theid, thedf in df.groupby(by=['Ad-Slot_Id'], axis=0):
    print theid
    print thedf.resample(resampletime, how='count')['Ad-Slot_Id']

This should help you get on your way.

Daan
  • 940
  • 10
  • 22