Could you explain the inner function inside count_words
function?
#17
-
Hello,
Let's apply this function on a dataframe:
The output would be:
I can understand this function except the inner function lines. I understant that we will count words using built-in class
Thank you in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Sure. df_name[column_name].map(inner_update) # call inner function So the parameter df_name[column_name].map(lambda doc: inner_update(doc)) # call inner function So it's basically the value of your "Text" column in the example. And as nested functions in Python have access to all parameters of the surrounding function, we can simply use |
Beta Was this translation helpful? Give feedback.
Sure.
inner_update
is called in this line:So the parameter
doc
toinner_update
is the value ofdf_name[column_name]
. To make it more clear, the code line above is equivalent toSo it's basically the value of your "Text" column in the example.
And as nested functions in Python have access to all parameters of the surrounding function, we can simply use
preprocess
within the inner functions without explicit handover as a parameter.