← All Python interview questions

Z-score normalise a spend array with NumPy

MediumNumPyAmazonMyntra

Before clustering customers, monthly spend has to be put on a comparable scale. The standard move is a z-score: subtract the mean and divide by the standard deviation.

Write a function zscore(values) that takes a list of numbers and returns a list of z-scores, each rounded to 2 decimals. If the standard deviation is 0, return a list of 0.0 of the same length.

Practising alone only goes so far — our live cohorts pair Python and Pandas depth with dashboards, agentic analytics projects and mock interviews.

Explore the program