|
|
|
|
|
by ryan-duve
377 days ago
|
|
I wonder if the author would have thought Pandas feels less clunky if they knew about `.eval`? import pandas as pd
purchases = pd.read_csv("purchases.csv")
(
purchases.loc[
lambda x: x["amount"] < 10 * x.groupby("country")["amount"].transform("median")
]
.eval("total=amount-discount")
.groupby("country")["total"]
.sum()
)
|
|