简体   繁体   English

如何在 XIRR function 的 Pyxirr 库中循环分组数据付款和日期

[英]How to loop over grouped data Payments and dates in Pyxirr library in XIRR function

I am trying to get XIRR for each customer with multiple entries with dates and payments in float.我正在尝试为每个客户获取 XIRR,其中包含多个日期和付款浮动的条目。 I want to find XIRR for each customer by grouping them with Unique ID我想通过使用唯一 ID 对每个客户进行分组来找到每个客户的 XIRR

Code I am trying我正在尝试的代码

import pandas as pd

from pyxirr import xirr

result = df.groupby("ID")[["date","payment"]].apply(xirr)`

where df id my dataframe and ID, date and payment are my columns其中 df id my dataframe 和 ID、日期和付款是我的列

I am getting error as InvalidPaymentsError: negative and positive payments are required我收到错误,因为InvalidPaymentsError:需要负数和正数付款

In order to calculate XIRR, you need both positive and negative payments.为了计算 XIRR,您需要正数和负数付款。 This error means that some of the groups have only negative or only positive payments.此错误意味着某些组只有负付款或只有正付款。 You can suppress this exception by using silent=True parameter ( link ).您可以通过使用silent=True参数 ( link ) 来抑制此异常。

df.groupby("ID")[["date","payment"]].apply(xirr, silent=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM