简体   繁体   中英

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. I want to find XIRR for each customer by grouping them with Unique ID

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

I am getting error as InvalidPaymentsError: negative and positive payments are required

In order to calculate XIRR, you need both positive and negative payments. 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 ).

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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