Python Data Frame resample on micro second

前提是你 提交于 2019-12-03 10:16:27

问题


I am working with resampling data frame and it works on hours, days mins, but doesn't resample less then sec. Program just hangs even on short time span. So am I missing something?

I tried 0.000001S, U etc... Nothing worked so far.

my time format: 2015-08-29 19:30:47.015506

you can see varable sf represent resampling freq.

grph = df.set_index('Date and Time').resample(sf, len).astype(int)

How can I resample data frame on micro seconds granularity?


回答1:


sf = "1U" #for one microsecond

For milliseconds/microseconds/seconds use:

L       milliseonds
U       microseconds
S       seconds

Full doc:

B       business day frequency
C       custom business day frequency (experimental)
D       calendar day frequency
W       weekly frequency
M       month end frequency
BM      business month end frequency
CBM     custom business month end frequency
MS      month start frequency
BMS     business month start frequency
CBMS    custom business month start frequency
Q       quarter end frequency
BQ      business quarter endfrequency
QS      quarter start frequency
BQS     business quarter start frequency
A       year end frequency
BA      business year end frequency
AS      year start frequency
BAS     business year start frequency
BH      business hour frequency
H       hourly frequency
T       minutely frequency
S       secondly frequency
L       milliseonds
U       microseconds
N       nanoseconds



回答2:


If I understand your problem correctly you can't resample microseconds to another frequency that is less than a second, right? I made a toy example and there doesn't seem to be a problem though:

import pandas as pd
import numpy as np

np.random.seed(0)
index=pd.date_range('22/10/2010', periods=100000, freq='U')
example=pd.Series(index=index,data=np.random.randn(100000))
example.resample('ms',how='sum')

This gives the expected output.

(I think your problem is that you are trying to resample data that are in a microsecond format to microseconds itself, which doesn't make any sense. You want to either upsample or downsample (as in my example).)



来源:https://stackoverflow.com/questions/32313741/python-data-frame-resample-on-micro-second

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!