我有一個名爲rollTestLogReturnsData數據幀是由日期更改數據幀索引整數
BBG.KABN.S BBG.TKA.S BBG.CON.S BBG.ISAT.S
date
2015-02-17 -0.005821 -0.016792 -0.016111 0.001028
2015-02-18 0.000588 0.019169 -0.000307 -0.001832
2015-02-19 0.005041 -0.007580 0.004164 0.003923
2015-02-20 -0.004881 0.008011 0.007047 -0.000307
2015-02-23 0.007468 -0.011277 -0.003273 0.004355
然後我創建一個名爲rollReturnRandomDf另據幀按日期索引是從rollTestLogReturnsData行的隨機選擇索引。這是通過使用構造:
rollReturnRandomDf = rollTestLogReturnsData.ix[np.random.choice(rollTestLogReturnsData.index, len(rollTestLogReturnsData.index))]
其可以類似於:
BBG.KABN.S BBG.TKA.S BBG.CON.S BBG.ISAT.S
date
2015-02-20 -0.004881 0.008011 0.007047 -0.000307
2015-02-20 -0.004881 0.008011 0.007047 -0.000307
2015-02-19 0.005041 -0.007580 0.004164 0.003923
2015-02-17 -0.005821 -0.016792 -0.016111 0.001028
2015-02-20 -0.004881 0.008011 0.007047 -0.000307
請注意,索引日期可以是用於多行相同的(在這種情況下2015年2月20日發生3次) 。當我詢問rollTestLogReturnsData時,問題就開始了。
有沒有辦法重新索引rollTestLogReturnsData數據框與intergers所以它看起來像:
BBG.KABN.S BBG.TKA.S BBG.CON.S BBG.ISAT.S
Index
0 -0.004881 0.008011 0.007047 -0.000307
1 -0.004881 0.008011 0.007047 -0.000307
2 0.005041 -0.007580 0.004164 0.003923
3 -0.005821 -0.016792 -0.016111 0.001028
4 -0.004881 0.008011 0.007047 -0.000307
我曾嘗試操作上面的代碼行,但都未能拿出一個辦法做到這一點。有人能幫我一個忙嗎?
非常感謝
如果能幫助您解決您的問題,請您接受並提出我的答案嗎?非常感謝。 :-) –