Suppose I have the following Pandas DataFrame. I want to compute the time (in seconds) since the last observation of each ip
. Notice that the data is not necessarily ordered.
dict = {'ip':[123, 326, 123, 326], 'hour': [14, 12, 12, 1], 'minute': [54, 23, 41, 8], 'second': [45, 29, 19, 33]}
df = pd.DataFrame(dict, columns = dict.keys())
ip hour minute second
0 123 14 54 45
1 326 12 23 29
2 123 12 41 19
3 326 1 8 33
For example, I would like to add a column on the first entry saying that when ip
123 was captured by the second time, the equivalent in seconds of (14:54:45 - 12:41:19) had been elapsed since the last appearence in the dataset.
I am trying something with groupby
but with no success. Any ideas?
Thanks in advance!!!