Functions with additional arguments
Let's add some arguments to the function definition!
Numeric data in scores
represent students' performance scaled between 0 and 100. Your task is to rescale this data to an arbitrary range between low
and high
. Rescaling should be done in a linear fashion, i.e. for any data point \(x\) in a column:
\(x_{new}\) = \(x\frac{high -low}{100} + low\)
To do rescaling, you'll have to define the function rescale()
. Remember, the operation written above can be applied to Series directly. After defining the function, you'll have to apply it to the specified columns of scores
.
This exercise is part of the course
Practicing Coding Interview Questions in Python
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
def rescale(series, low, high):
# Define the expression to rescale input series
return ____
# Rescale the data in cols to lie between 1 and 10
cols = ['math score', 'reading score', 'writing score']
scores[cols] = scores[cols].____
print(scores[cols].head())