Calmcode - pandas pipe: introduction

Introduction to Pandas Pipe

1 2 3 4 5 6 7 8 9

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('')

df2 = (df
  .assign(date=lambda d: pd.to_datetime(d['date']))
  .sort_values(['currency_code', 'date'])
  .agg(n=('date', 'count')))

df.loc[lambda d: d['currency_code'].isin(df2[df2['n'] >= 32].index)]

That df2 especially is a code smell.