4 ms·
Lots of readers of my book, Effective Pandas, say it helps them feel more like they are used to with R... (I've never used R myself, but certainly have some ve
by __mharrison__ 1y ago
Lots of readers of my book, Effective Pandas, say it helps them feel more like they are used to with R...
(I've never used R myself, but certainly have some very strong opinions about Pandas after having written 3 books about it.)
- ivansavz 1y agoHi Matt! Big fan. The first that I thought when I read this article was "How would Matt use his .assign-chain-kung-fu on this one" and I tried import pandas as pd purchases = pd.read_csv("https://www.sumsar.net/blog/pandas-feels-clunky-when-coming-from-r/purchases.csv") (purchases .assign(country_median=lambda df: df.groupby("country")["amount"].transform("median") ) .query("amount <= country_median * 10") .groupby("country") .assign(total=lambda df: (df["amount"] - df["discount"]).sum()) ) but it seems 'DataFrameGroupBy' object has no attribute 'assign' so its not that simple, though with a slight re-ordering of the chain operations, it works cf. https://news.ycombinator.com/item?id=44236487 https://news.ycombinator.com/item?id=44236487