An outlier is a value far from the rest, like one customer who spent many times more than everyone else. Some summaries bend toward outliers and some don't, so you should know which number you are reading.
.mean() gives back the average: the sum divided by the count. .median() gives back the middle value once the values are sorted, so half are below it and half above. One big value pulls the mean far up and leaves the median alone:
prices = pd.Series([10, 20, 30, 40, 400])
print(prices.mean(), prices.median()) # 100.0 30.0
.quantile(0.99) gives back the value that 99% of the values are at or below: a line for "the top 1%". series[series > x] keeps only the values above x. .replace(a, b) gives back a copy with every a turned into b; you'll use it to fake a typing mistake and see what one wrong number does.
Your script must print:
Mean: 189.93 Median: 158.0
Top 1% from: 655.1
customer_id orders spent
0 1 6 720
62 63 4 666
73 74 6 665
Mean without them: 184.94
With one typo, mean: 211.53 median: 158.0
Half the customers spent at most 158.0; one wrong number moved the mean from 189.93 to 211.53 and the median not at all.
Your task: compare the mean and the median of spent, find where the top 1% starts and who is in it, and print the mean without them. Then turn the 720 into 7200 and show what that one typo does to the mean and to the median.
Assignment
Follow the Coding Tutorial to measure the outliers in spent and show how one wrong number moves the mean but not the median.
Hint
Round the means and the cut with round(x, 2); the median prints as it is. replace gives back a new Series and leaves spent unchanged.
Free plan: 30 tutor messages. PRO is unlimited.
