logo

... pandas pipe: introduction



Notes

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)]

That df2 especially is a code smell.

Feedback? See an issue? Something unclear? Feel free to mention it here.



If you want to be kept up to date, consider signing up for the newsletter.