Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Or with and .assign:

    (
        purchases.loc[
            lambda x: x["amount"] < 10 * x.groupby("country")["amount"].transform("median")
        ]
        .assign(total=lambda df: df["amount"] - df["discount"])
        .groupby("country")["total"]
        .sum()
        .reset_index()  # to produce a DataFrame result
    )


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: