Make the timestamps interesting
In [23]: df_orig2['timestamp'] = df_orig2['timestamp']+df_orig2.index.values
In [24]: df_orig2
Out[24]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3000 entries, 0 to 2999
Data columns (total 7 columns):
index 3000 non-null values
dst_ip 3000 non-null values
payload 3000 non-null values
payload_response 3000 non-null values
payload_type 3000 non-null values
src_ip 3000 non-null values
timestamp 3000 non-null values
dtypes: int64(5), object(2)
In [25]: df_orig2.head()
Out[25]:
index dst_ip payload payload_response payload_type src_ip timestamp
0 0 28 #live? #live 9437184 -1 1377186527
1 1 25 #live? #live 9437184 -1 1377186528
2 2 24 #live? #live 9437184 -1 1377186529
3 0 28 #live? #live 9437184 -1 1377186530
4 1 25 #live? #live 9437184 -1 1377186531
This is a vectorized groupby like what you are doing, but very fast
In [37]: df_orig2['grp'] = (df_orig2['timestamp'] % 100)/25
In [42]: df_orig2.groupby('grp')['payload_type'].mean()
Out[42]:
grp
0 9437184
1 9437184
2 9437184
3 9437184
Name: payload_type, dtype: int64
However, you might want to convert to a datetime based column
In [27]: df = df_orig2.copy()
Convert from seconds since epoch
In [28]: df['timestamp'] = pd.to_datetime(df['timestamp'],unit='s')
In [29]: df
Out[29]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 3000 entries, 0 to 2999
Data columns (total 7 columns):
index 3000 non-null values
dst_ip 3000 non-null values
payload 3000 non-null values
payload_response 3000 non-null values
payload_type 3000 non-null values
src_ip 3000 non-null values
timestamp 3000 non-null values
dtypes: datetime64[ns](1), int64(4), object(2)
Resample at 15s intervals (not the same as above, but you get the idea)
In [48]: df.set_index('timestamp').resample('15s',how=np.mean).head()
Out[48]:
index dst_ip payload_type src_ip
timestamp
2013-08-22 15:48:45 0.923077 25.846154 9437184 -1
2013-08-22 15:49:00 1.000000 25.666667 9437184 -1
2013-08-22 15:49:15 1.000000 25.666667 9437184 -1
2013-08-22 15:49:30 1.000000 25.666667 9437184 -1
2013-08-22 15:49:45 1.000000 25.666667 9437184 -1