News for hackers. Stuff that matters.
Re:Modern Pandas (Part 2): Method Chaining by swied on Sunday May 01, 2022 @05:25PM (#31228829)
What about when the steps don't return a data frame object, like 'groupby'? Then, you will have to think about coming up a name other than 'df'. Save your mental energy for making comments. Here's an example...

    # Per store revenue for high price items   
    df_agg = (
      df1
      .query("unit_price > 400")
      .groupby('store_id','store_name')
      .agg({'revenue':     np.sum, 
            'customer_id': 'nunique'})
    )
Re:Modern Pandas (Part 2): Method Chaining by oneoff786 on Sunday May 01, 2022 @06:45PM (#31229461)
Groupby agg is a bit of an exception. It’s returning something that is very different from the original. Not just a modification, but a different table that summarizes the original. You ought to be assigning it to a new variable.

Groupby->agg is a good one to chain because you don’t want the intermediary almost ever.

Edit: also, I never understand people who use query. That just seems like it’s begging for problems later on. .loc for life.