Calmcode - pandas pipe: new

Larger Pipeline Steps in Pandas

1 2 3 4 5 6 7 8 9

You can add this step to the pipeline to get inflation numbers.

@log_step
def add_inflation_features(dataf):
    return (dataf
            .assign(local_inflation=lambda d: d.groupby('name')['local_price'].diff()/d['local_price'])
            .assign(dollar_inflation=lambda d: d.groupby('name')['dollar_price'].diff()/d['dollar_price']))

clean_df = (df
  .pipe(start_pipeline)
  .pipe(set_dtypes)
  .pipe(remove_outliers, min_row_country=20)
  .pipe(add_inflation_features))

Remember that it is relatively easy to make a new function, as long as you make a temporary variable to save the current dataframe into.