Build the table a data team would share before cleaning. Store a DataFrame in result with one row per store, sorted by store, and these columns:
storelower and upper: that store's 1.5 × IQR fences, rounded to 2 decimalsn_outliers: how many of its payments are outside themimport 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.