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.
本练习是课程的一部分
Practicing Coding Interview Questions in Python
交互式实操练习
通过完成这段示例代码来试试这个练习。
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())