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()
)
(
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
)
(I've never used R myself, but certainly have some very strong opinions about Pandas after having written 3 books about it.)
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=44236487Yes! Very much so. I'm in the final stages of cooking it right now, hoping to make it available for sale in the coming months.
Statistics is by far the hardest subject I've had to write about, as I had to (re)learn pretty much everything. I did several rewrites (working on tis book for the past seven years!), but now it's finally ready to ship. You can check out the notebooks from the book here: https://nobsstats.com/ and a detailed outline here https://docs.google.com/document/d/1fwep23-95U-w1QMPU31nOvUn...
ETA July for digital download, then one round of copy-editing, and September for first print version.
<shameless plug>For other adults interested in learning math, check out my (nonfree) book here: https://noBSmath.com/ PDF preview and sample chapter: https://minireference.com/static/excerpts/noBSmath_v5_previe... I also have a longer book that includes calculus and physics (cf. links in profile). </shameless plug>
- https://minireference.com/static/conceptmaps/math_concepts.p...
- https://minireference.com/static/conceptmaps/math_and_physic...
- https://minireference.com/static/conceptmaps/linear_algebra_...
<shameless plug>For other adults interested in learning math, check out my (nonfree) book here: https://noBSmath.com/ PDF preview and sample chapter: https://minireference.com/static/excerpts/noBSmath_v5_previe... I also have a longer book that includes calculus and physics (cf. links in profile). </shameless plug>
I started doing it to cope with severe unmedicated ADHD. I found the only way I could get any work done was to turn off my phone and unplug the router.
(I downloaded offline docs, and if I got really stuck, made a note of what to Google later and just switched tasks.)
I then found that I enjoyed getting stuff done so much, that I'd usually keep it off until after lunch.
I was thinking of scaling this up by adding Sunday too, but offline mornings might be even better... I'll look into adding a schedule in the router. I think it might be helpful to program the rule to start in the desired bedtime in the evening to make the pixel devices unexciting and incentivize reading old school books (the most efficient technology for getting me to sleep).
I've heard the advice don't touch the phone/email first thing in the morning so many times, but I can never stick to it, but if my "habit" is enforced at the network layer, I think it is doable ;)
UPDATE: Apparently iOS has a built in automation tool Shortcuts app, which allowed me to schedule this, see https://imgur.com/a/TsQJak3 I added similar rulesets to the router. Watch out world, Ivan's productivity is going to skyrocket!
Here is a notebook with some more graphs and visualizations of the CLT: https://nobsstats.com/site/notebooks/28_random_samples/#samp...
runnable link: https://mybinder.org/v2/gh/minireference/noBSstats/main?labp...