将Pandas DataFrame重新采样到每月一个工作日的偏移量

时间:2018-10-11 10:06:24

标签: python pandas

我有一个包含工作日索引的价格数据的数据框。我想将其重新采样为每月数据(使用Resampler对象上的max()方法),但得到的索引是该月的第x个工作日,而不是“ M”或“ BM”重新采样。

要简单地重新采样到一个工作月结束,我可以执行以下操作:

INFO: From Compiling external/nccl_archive/src/collectives/device/min_all_reduce.cu.cc:
ptxas warning : Too big maxrregcount value specified 96, will be ignored
INFO: From Compiling external/nccl_archive/src/collectives/device/max_all_reduce.cu.cc:
ptxas warning : Too big maxrregcount value specified 96, will be ignored
ERROR: /home/ubuntu/.cache/bazel/_bazel_ubuntu/3be25c7517fcab2b83999fe3669ecd1f/external/nccl_archive/BUILD.bazel:139:1: C++ compilation of rule '@nccl_archive//:device_code' failed (Exit 1)
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc:19:2: warning: #warning "crt/link.stub is an internal header file and must not be used directly.  Please use cuda_runtime_api.h or cuda_runtime.h instead." [-Wcpp]
 #warning "crt/link.stub is an internal header file and must not be used directly.  Please use cuda_runtime_api.h or cuda_runtime.h instead."
  ^
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc: In function 'void __cudaRegisterLinkedBinary(const __fatBinC_Wrapper_t*, void (*)(void**), void*)':
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc:140:5: error: '__NV_EXTRA_INITIALIZATION' was not declared in this scope
     __NV_EXTRA_INITIALIZATION
     ^
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc:144:5: error: '__NV_EXTRA_FINALIZATION' was not declared in this scope
     __NV_EXTRA_FINALIZATION
     ^
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc:145:23: warning: statement has no effect [-Wunused-value]
     for (__i = 0; __i < NUM_PRELINKED_OBJECTS; ++__i) {
                       ^
bazel-out/k8-opt/bin/external/nccl_archive/device_code.cc:145:53: error: expected ';' before ')' token
     for (__i = 0; __i < NUM_PRELINKED_OBJECTS; ++__i) {

但是我希望重新采样的索引如下:

monthly_df = daily_df.resample('BM').max()

如果我只是想重新采样到last()而不是max(),我可以简单地重新索引。即

bd_offset = 5
new_index = daily_df.resample('BM').last().index + pd.datetools.BDay(bd_offset)

但是我希望每个月度组的monthly_df = daily_df.reindex(new_index) 而不是最后一个。

任何帮助将不胜感激。

0 个答案:

没有答案