Hi
on Mission 345 Slide 2 - Apply a Function Element-wise Using the Map and Apply Methods. In the lesson there is this statement
Note that these methods both take a function as a parameter. Because we’re using the function as a parameter, we pass it into the function without the parentheses. For example, if we were working with a function called transform , we’d pass it into the apply() method as follows:
def transform(val):
return val
Series.apply(transform)
The missing parentheses are after transform. Normally when you call a function you need to put the function inputs inside parentheses just after the function name.
For example, if we make a function “sqrt”, that calculates the square root of a number:
def sqrt(number):
return number**(0.5)
Then, to use the function, normally you code:
print(sqrt(4))
The output would be 2.
What is special about using a function as a parameter for series.apply(), is that you don’t have to specify the function inputs in parentheses, because series.apply() is coded to use the values of the series as the inputs to the function you are applying.
Please let me know if I am not clear with the explanation and I can try another example.