Pandas code can get quite nasty inside of your jupyter notebook. It's not just the syntax, it's the infinite amount of scrolling too. In this series of videos we're going to explore a way to clean this up. This series of videos is inspired by the modern pandas blogposts originally written by Tom Augspurger.
The code shown below does it's job, but it is bound to get out of hand.
import pandas as pd df = pd.read_csv('https://calmcode.io/datasets/bigmac.csv') df2 = (df .assign(date=lambda d: pd.to_datetime(d['date'])) .sort_values(['currency_code', 'date']) .groupby('currency_code') .agg(n=('date', 'count'))) df.loc[lambda d: d['currency_code'].isin(df2[df2['n'] >= 32].index)]
df2 especially is a code smell.
Feedback? See an issue? Feel free to mention it here.
If you want to be kept up to date, consider getting the newsletter.