₹2,000 is normal in Mumbai but would be huge in Pune, so outliers must be found per store. Work out Q1, Q3 and the 1.5 × IQR fences within each store and store the txn_id values outside their own store's fences in result (a list in table order).
import pandas as pd
import numpy as np
txns = pd.DataFrame({
"txn_id": list(range(1, 25)),
"store": ["Pune"] * 8 + ["Mumbai"] * 8 + ["Delhi"] * 8,
"amount": [420, 515, 480, 610, 455, 9800, 530, 470,
2100, 2350, 1980, 2240, 2500, 2050, 150, 2300,
880, 940, 1020, 860, 990, 910, 99999, 1050],
"qty": [1, 2, 1, 2, 1, 3, 2, 1,
1, 1, 2, 1, 30, 1, 1, 2,
1, 2, 2, 1, 1, 2, 1, 2],
})Store your final answer in a variable named result.
Each hint gives a little more help. Try on your own first.
Run your code to see the output here.