【问题标题】:Aggregating data with different level of details in Pandas Python在 Pandas Python 中聚合具有不同细节级别的数据
【发布时间】:2021-10-26 00:23:56
【问题描述】:

我在 Python Pandas 中有一个数据集,其结构类似于下表。

我正在尝试添加一个新列,用于计算每笔贷款的总 NPV(将每笔贷款的“贷款发放日期计算的贷款支付的 NPV”相加)。我希望结果如下所示:

我曾尝试编写 for 循环,但我不断收到错误。谁能帮我解决这个问题?

【问题讨论】:

标签: python pandas aggregation


【解决方案1】:
df.groupby("LoanID",as_index=False)["NPV of loan payment calculated at the time of loan Issue date"].sum()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-11-01
    • 2013-03-16
    • 1970-01-01
    • 2018-10-07
    • 1970-01-01
    • 2019-02-02
    • 2019-11-04
    相关资源
    最近更新 更多