Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫不规则时间序列的下采样_Python_Pandas - Fatal编程技术网

Python 熊猫不规则时间序列的下采样

Python 熊猫不规则时间序列的下采样,python,pandas,Python,Pandas,我有一个熊猫的时间序列,看起来像这样: 2012-01-01 00:00:00.250000 12 2012-01-01 00:00:00.257000 34 2012-01-01 00:00:00.258000 45 2012-01-01 00:00:01.350000 56 2012-01-01 00:00:02.300000 78 2012-01-01 00:00:03.200000 89 2012-01-01 00:00:03.500000 9

我有一个熊猫的时间序列,看起来像这样:


2012-01-01 00:00:00.250000    12
2012-01-01 00:00:00.257000    34
2012-01-01 00:00:00.258000    45
2012-01-01 00:00:01.350000    56
2012-01-01 00:00:02.300000    78
2012-01-01 00:00:03.200000    89
2012-01-01 00:00:03.500000    90
2012-01-01 00:00:04.200000    12
有没有一种方法可以在不与1秒边界对齐的情况下将其采样降至1秒数据?例如,是否有一种方法可以获取此数据(假设使用采样时间之前或当天出现的最新值进行下采样):


创建一个DateTimeIndex,频率为1秒,偏移量为四分之一秒,如下所示

index = pd.date_range('2012-01-01 00:00:00.25', 
                      '2012-01-01 00:00:04.25', freq='S')
使您的数据符合此索引,并“向前填充”以按您在所需结果中显示的方式进行下采样

s.reindex(index, method='ffill')
                            data
2012-01-01 00:00:00.250000    12
2012-01-01 00:00:01.250000    45
2012-01-01 00:00:02.250000    56
2012-01-01 00:00:03.250000    89
2012-01-01 00:00:04.250000    12
s.reindex(index, method='ffill')
                            data
2012-01-01 00:00:00.250000    12
2012-01-01 00:00:01.250000    45
2012-01-01 00:00:02.250000    56
2012-01-01 00:00:03.250000    89
2012-01-01 00:00:04.250000    12