我有一个看起来像这样的数据框:
我在末尾附加了一个聚合行,该行计算列的均值,而忽略空值。在这里查看我的代码:
repayments_amt_pivot.loc['Aggregated'] = repayments_amt_pivot.iloc[:, 3:].mean(skipna=True)
但是,我实际上需要计算的百分比的加权总和乘以principal_due_per_month中的比例。
在这种情况下,对于第4个月,第0行将乘以(27,845 / 27,845 + 310,506 + 659,705 + 1,433,121)。
对于第3个月,第4行将乘以(1,941,036 / 27,845 + 310,506 + 659,705 + 1,433,121 + 1,941,036)
等
任何帮助将不胜感激,因为我无法弄清楚这一点!
有关如何在excel中进行计算的屏幕截图,请参见以下内容。
数据:
pd.DataFrame([{'$ Amount Due': 27845.312793586978,
'Month 0': 56.479872661140476,
'Month 1': 92.94027983726657,
'Month 2': 100.00000000000003,
'Month 3': 100.00000000000003,
'Month 4': 100.00000000000003},
{'$ Amount Due': 310505.5597382864,
'Month 0': 78.34839385064039,
'Month 1': 79.58303224427453,
'Month 2': 79.58303224427453,
'Month 3': 81.43498983472573,
'Month 4': 92.54673537743292},
{'$ Amount Due': 659705.2173778547,
'Month 0': 90.79718901057414,
'Month 1': 97.8418387417451,
'Month 2': 97.85768670717538,
'Month 3': 97.85768670717538,
'Month 4': 97.85768670717538},
{'$ Amount Due': 1433121.318250646,
'Month 0': 91.7207168764003,
'Month 1': 94.34283888419282,
'Month 2': 94.51326381568556,
'Month 3': 94.8581612152927,
'Month 4': 94.91544740629973},
{'$ Amount Due': 1941036.1276433321,
'Month 0': 79.75029644420579,
'Month 1': 85.62252846197367,
'Month 2': 86.59251760542142,
'Month 3': 86.70920561577343,
'Month 4': np.nan},
{'$ Amount Due': 3448302.2801859295,
'Month 0': 75.83697471065258,
'Month 1': 83.6700011095642,
'Month 2': 86.16217213969533,
'Month 3': np.nan,
'Month 4': np.nan},
{'$ Amount Due': 3190042.0279137697,
'Month 0': 76.69574360823212,
'Month 1': 85.4625418697537,
'Month 2': np.nan,
'Month 3': np.nan,
'Month 4': np.nan},
{'$ Amount Due': 2614440.2956102462,
'Month 0': 74.87175589142862,
'Month 1': np.nan,
'Month 2': np.nan,
'Month 3': np.nan,
'Month 4': np.nan}])