0

I am relatively new to Pandas, and was hoping for guidance on the most efficient and clean way to handle multiple rules/masks to the same dataframe column.

I have two unique and independent conditions working:

Condition 1

df["price"]= df["price"].mask(df["price"].eq("£ 0.00"), df["product_price_old"])
df.drop(axis=1, inplace=True, columns='product_price_old')

Condition 2

df["price"] = df["price"].mask(df["product_price_old"].gt(df["price"]), df["product_price_old"])
df.drop(axis=1, inplace=True, columns='product_price_old')

What is the best syntax in Pandas to merge these conditions together and remove the duplication?

Would a separate Python function and call it via .agg? I came across a .pipe in the docs earlier, would this be a suitable use case?

Any help would be appreciated.

dimButTries
  • 661
  • 7
  • 15
  • could you share a small example of your dataframe and the output you're expecting? – Emi OB Nov 08 '21 at 15:36
  • Does this answer your question? [Pandas Mask on multiple Conditions](https://stackoverflow.com/questions/56093625/pandas-mask-on-multiple-conditions) – ImSo3K Nov 08 '21 at 16:26

0 Answers0