python - How to resample starting from the first element in pandas? -
i resampling following table/data:
timestamp l_x l_y l_a r_x r_y r_a 2403950 621.3 461.3 313 623.3 461.8 260 2403954 622.5 461.3 312 623.3 462.6 260 2403958 623.1 461.5 311 623.4 464 261 2403962 623.6 461.7 310 623.7 465.4 261 2403966 623.8 461.5 309 623.9 466.1 261 2403970 620.9 461.4 309 623.8 465.9 259 2403974 621.7 461.1 308 623 464.8 258 2403978 622.1 461.1 308 621.9 463.9 256 2403982 622.5 461.5 308 621 463.4 255 2403986 622.4 462.1 307 620.7 463.3 254
the table goes on , on that. timestamps in milliseconds. did following resample 100milliseconds bin time:
i changed timestamp index datetime format
df.index = pd.to_datetime((df.index.values*1e6).astype(int))
i resampled in 100milliseconds:
df = df.resample('100l')
the resulting resampled data following:
timestamp l_x l_y l_a r_x r_y r_a 2403900 621.3 461.3 313 623.3 461.8 260 2404000 622.5 461.3 312 623.3 462.6 260 2404100 623.1 461.5 311 623.4 464 261 2404200 623.6 461.7 310 623.7 465.4 261 2404300 623.8 461.5 309 623.9 466.1 261
as can see first bin time 2403900, 50milliseconds behind first timestamp index of original table. wanted bin time start first timestamp index original table, 2403950. following:
timestamp l_x l_y l_a r_x r_y r_a 2403950 621.3 461.3 313 623.3 461.8 260 2404050 622.5 461.3 312 623.3 462.6 260 2404150 623.1 461.5 311 623.4 464 261 2404250 623.6 461.7 310 623.7 465.4 261 2404350 623.8 461.5 309 623.9 466.1 261
you can specify offset:
df.resample('100l', loffset='50l')
update
of course can calculate offset:
offset = df.index[0] % 100 df.index = pd.to_datetime((df.index.values*1e6).astype(int)) df.resample('100l', loffset='{}l'.format(offset))
Comments
Post a Comment