When working through code I usually build long lines like this, but already I've forgotten what’s going on, and I find having it like this is hard to read. I would have to deconstruct and run each section to see what is really going on.
BUT when teaching myself the resources I learnt from said advanced users would use one line of code when beginners would use many.
So my question really is:
Would it be better to have this one line (kept as it is)? And if so how can it be formatted to be under 79 characters (as per PEP8)?
Or is it better to break this down into chunks so it’s easier to come back to at a later date (or is it strange I can't understand it like this)?
top_products_for_customer_group = stock_trans[(stock_trans["SA_DACCNT"].isin(customer_seg_df[self.customer_seg_df["Label"] == customer_seg_df[self.customer_seg_df["SA_DACCNT"] == acc]["Label"].iloc[0]]["SA_DACCNT"]))].groupby(["SA_PRODUCT", "SA_DESC"]).count()["SA_ACCOUNT"].reset_index().sort_values("SA_ACCOUNT", ascending=False)