Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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 熊猫:当包含更多数据时,asfreq会出现奇怪的行为_Python_Pandas - Fatal编程技术网

Python 熊猫:当包含更多数据时,asfreq会出现奇怪的行为

Python 熊猫:当包含更多数据时,asfreq会出现奇怪的行为,python,pandas,Python,Pandas,我在使用asfreq时遇到问题。从下面可以看出,当我从ts系列中包含一个以上的值来执行asfreq on时,结果ts2将所有值设置为第一个值。我的期望是,除了可能包含一个新的价值之外,根本不会有任何变化。对我来说,这似乎是一个错误,还是我遗漏了什么 In [571]: ts Out[571]: 2014-02-24 13:26:26.941000 1.142483 2014-02-24 14:47:11.480000 -0.900430 2014-02-24 15:09:36.490

我在使用asfreq时遇到问题。从下面可以看出,当我从ts系列中包含一个以上的值来执行asfreq on时,结果ts2将所有值设置为第一个值。我的期望是,除了可能包含一个新的价值之外,根本不会有任何变化。对我来说,这似乎是一个错误,还是我遗漏了什么

In [571]: ts
Out[571]: 
2014-02-24 13:26:26.941000    1.142483
2014-02-24 14:47:11.480000   -0.900430
2014-02-24 15:09:36.490000   -0.998898
2014-02-24 15:48:31.534000    1.242197
2014-02-24 15:49:32.529000   -0.301316
2014-02-24 15:58:41.321000    0.342022
2014-02-24 16:05:42.752000   -0.876856
2014-02-24 16:10:21.501000   -1.050685
2014-02-24 16:16:47.204000    1.391424
2014-02-24 16:18:48.296000    1.048143
2014-02-24 16:19:52.346000   -0.823974
2014-02-24 16:22:13.665000   -0.689560
2014-02-24 16:24:13.760000   -0.323252
2014-02-24 16:26:15.155000   -1.095331
2014-02-24 16:29:58.235000   -0.185681
...
Length: 4455

In [572]: ts2 = ts[0:2128].asfreq('10Min',method='pad')

In [573]: ts2
Out[573]: 
2014-02-24 13:26:26.941000    1.142483
2014-02-24 13:36:26.941000    1.142483
2014-02-24 13:46:26.941000    1.142483
2014-02-24 13:56:26.941000    1.142483
2014-02-24 14:06:26.941000    1.142483
2014-02-24 14:16:26.941000    1.142483
2014-02-24 14:26:26.941000    1.142483
2014-02-24 14:36:26.941000    1.142483
2014-02-24 14:46:26.941000    1.142483
2014-02-24 14:56:26.941000   -0.900430
2014-02-24 15:06:26.941000   -0.900430
2014-02-24 15:16:26.941000   -0.998898
2014-02-24 15:26:26.941000   -0.998898
2014-02-24 15:36:26.941000   -0.998898
2014-02-24 15:46:26.941000   -0.998898
...
Freq: 10T, Length: 7076

In [574]: ts2 = ts[0:2129].asfreq('10Min',method='pad')

In [575]: ts2
Out[575]: 
2014-02-24 13:26:26.941000    1.142483
2014-02-24 13:36:26.941000    1.142483
2014-02-24 13:46:26.941000    1.142483
2014-02-24 13:56:26.941000    1.142483
2014-02-24 14:06:26.941000    1.142483
2014-02-24 14:16:26.941000    1.142483
2014-02-24 14:26:26.941000    1.142483
2014-02-24 14:36:26.941000    1.142483
2014-02-24 14:46:26.941000    1.142483
2014-02-24 14:56:26.941000    1.142483
2014-02-24 15:06:26.941000    1.142483
2014-02-24 15:16:26.941000    1.142483
2014-02-24 15:26:26.941000    1.142483
2014-02-24 15:36:26.941000    1.142483
2014-02-24 15:46:26.941000    1.142483
...
2014-04-14 14:16:26.941000    1.142483
2014-04-14 14:26:26.941000    1.142483
2014-04-14 14:36:26.941000    1.142483
Freq: 10T, Length: 7076

In [576]: ts2.max()
Out[576]: 1.1424827552686787

In [577]: ts2.min()
Out[577]: 1.1424827552686787
输出:

      Value
  Date                         
  2014-02-24 16:16:00  1.391424
  2014-02-24 16:18:00  1.048143
  2014-02-24 16:19:00 -0.823974
  2014-02-24 16:22:00 -0.689560
  2014-02-24 16:24:00 -0.323252
  2014-02-24 16:26:00 -1.095331
  2014-02-24 16:29:00 -0.185681

.asfreq
转换定期采样序列上的频率,您可能想
。重新采样
,您想做什么?我想创建一个频率更高且定期的序列。应在不规则时间戳处从现有值中填充值(正向填充)。文档中没有提到必须定期对原始系列进行采样。第一个ts2(ts2=ts[0:2128].asfreq('10Min',method='pad')是正确的(14:47之后是一个新值),但由于某些原因,当我包含一个以上的值/时间戳[2129]时,所有结果值都是相同的。使用重采样;对于没有频率的索引,asfreq没有多大意义
      Value
  Date                         
  2014-02-24 16:16:00  1.391424
  2014-02-24 16:18:00  1.048143
  2014-02-24 16:19:00 -0.823974
  2014-02-24 16:22:00 -0.689560
  2014-02-24 16:24:00 -0.323252
  2014-02-24 16:26:00 -1.095331
  2014-02-24 16:29:00 -0.185681