我在Pandas中有一个名为df_scenarioReport的数据框。
有2500种情景(称为数字)。我需要填写缺少的ShiftDays并线性插值ShiftValue以确定缺少的条目。
示例:
对于Index = FEDFUND,我的ShiftDays值为11美元。我想找到每个场景的线性插值。我想为ShiftDays 8返回2500个答案。
最后,鉴于我有多种货币和多种指数,实现这一目标的最快/最有效的方法是什么?
import pandas as pd
df_scenarioReport = pd.DataFrame({
'Scenario' : '1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1'.split(),
'Currency' : 'USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD USD ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR ZAR'.split(),
'Index' : 'LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR LIBOR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR JIBAR'.split(),
'Tenor' : '1 7 14 21 30 60 90 120 150 180 210 240 540 630 720 81 900 990 1 7 14 21 30 60 90 120 150 180 210 240 540 630 720 81 900 990 1 7 14 21 30 60 90 120 150 180 210 240 540 630 720 81 900 990'.split(),
'Value' : '0.091867121 0.142505739 0.404330105 0.852004808 0.594887446 0.015180395 0.060961216 0.292239552 0.425478075 0.19182094 0.129239953 0.142229009 0.019297533 0.046758472 0.888882534 0.746739281 0.535606143 0.704372452 0.694322817 0.52574823 0.473401721 0.963138328 0.918588002 0.662963754 0.462752537 0.388765765 0.853134788 0.909756898 0.898369698 0.99315306 0.721165509 0.457227048 0.028771065 0.529281472 0.144257999 0.40902023 0.111119432 0.624777636 0.651348973 0.402240327 0.533277559 0.516840073 0.661178189 0.088462112 0.833841068 0.646918966 0.968806721 0.681352673 0.629696871 0.900297606 0.589721176 0.843034738 0.699369307 0.371361928'.split()})
df_DFs_reduced = pd.DataFrame({
'Day' : '1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45'.split()})
预期结果:
Scenario Currency Index Day Value
1 USD LIBOR 1 0.091867121
1 USD LIBOR 2 0.10030689
1 USD LIBOR 3 0.10874666
1 USD LIBOR 4 0.11718643
1 USD LIBOR 5 0.1256262
1 USD LIBOR 6 0.134065969
1 USD LIBOR 7 0.142505739
2 USD LIBOR 1 0.694322817
2 USD LIBOR 2 0.666227052
2 USD LIBOR 3 0.638131288
2 USD LIBOR 4 0.610035523
2 USD LIBOR 5 0.581939759
2 USD LIBOR 6 0.553843994
2 USD LIBOR 7 0.52574823