A z-score says how many standard deviations a value is from the mean: (x − mean) / std. Use the pandas std() (sample standard deviation).
Store the txn_id values whose amount has an absolute z-score above 3 in result (a list).
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.