是否有任何快速方法可以使用 pandas 工具在多年、多索引和每小时的数据集中每天随机抽样 N 小时?我的目标是为每一天和每一对 X、Y 获得 N 个随机小时。
如果我的数据看起来像这样:
In [21]: df
Out[21]:
Stuff
Date X Y
2004-01-01 02:00:00 0 1 1.047065
2004-01-01 03:00:00 0 1 -1.048725
2004-01-01 04:00:00 0 1 -0.245098
2004-01-01 05:00:00 0 1 0.452306
2004-01-01 02:00:00 2 3 0.100935
2004-01-01 03:00:00 2 3 -1.183009
2004-01-01 04:00:00 2 3 0.164260
2004-01-01 05:00:00 2 3 -1.013031
2004-01-01 02:00:00 4 2 -0.300900
2004-01-01 03:00:00 4 2 0.698377
2004-01-01 04:00:00 4 2 0.335517
2004-01-01 05:00:00 4 2 -0.421466
2004-01-01 02:00:00 7 9 -0.904358
2004-01-01 03:00:00 7 9 1.496770
2004-01-01 04:00:00 7 9 -0.966784
2004-01-01 05:00:00 7 9 0.101442
2004-01-02 02:00:00 0 1 0.771495
2004-01-02 03:00:00 0 1 -1.559194
2004-01-02 04:00:00 0 1 0.497352
2004-01-02 05:00:00 0 1 0.377913
2004-01-02 02:00:00 2 3 0.637454
2004-01-02 03:00:00 2 3 -0.381010
2004-01-02 04:00:00 2 3 1.973359
2004-01-02 05:00:00 2 3 0.390250
2004-01-02 02:00:00 4 2 0.948655
2004-01-02 03:00:00 4 2 0.234342
2004-01-02 04:00:00 4 2 0.766474
2004-01-02 05:00:00 4 2 -0.529767
2004-01-02 02:00:00 7 9 0.682759
2004-01-02 03:00:00 7 9 2.202768
2004-01-02 04:00:00 7 9 2.190237
2004-01-02 05:00:00 7 9 -1.641499
我希望得到类似于(如果 N = 2)的结果:
Stuff
Date X Y
2004-01-01 02:00:00 0 1 1.047065
2004-01-01 05:00:00 0 1 0.452306
2004-01-01 04:00:00 2 3 0.164260
2004-01-01 05:00:00 2 3 -1.013031
2004-01-01 02:00:00 4 2 -0.300900
2004-01-01 03:00:00 4 2 0.698377
2004-01-01 02:00:00 7 9 -0.904358
2004-01-01 05:00:00 7 9 0.101442
2004-01-02 03:00:00 0 1 -1.559194
2004-01-02 04:00:00 0 1 0.497352
2004-01-02 04:00:00 2 3 1.973359
2004-01-02 05:00:00 2 3 0.390250
2004-01-02 02:00:00 4 2 0.948655
2004-01-02 05:00:00 4 2 -0.529767
2004-01-02 04:00:00 7 9 2.190237
2004-01-02 05:00:00 7 9 -1.641499