Bringing it all together
1. Bringing it all together
It's now time to get you hands dirty using your newly acquired skills. Recall that, in the previous chapter, you wrote a function that would perform the following: it would take a DataFrame of twitter data and return a dictionary containing languages as keys and the number of times a tweet was written in a given language as values.2. Next exercises:
In the following exercises, you will write a function that processes a DataFrame and returns a dictionary with counts of occurrences in any column at all! By default, however, it will process a column called lang. This generalizes the previous function that you wrote. You will then generalize this further so that you can pass the function a DataFrame and any number of column names to perform the computation on an arbitrary number of columns.3. Add a default argument
Let's remind ourselves of the techniques necessary: recall that to define a function with a default argument, all that you need to do is provide that argument in the function header as you can see here.4. Flexible arguments: *args (1)
Next up, to write a function that you can pass an arbitrary number of arguments to, that is, flexible arguments, we use the arguments args as here, and then we can loop over all elements of args in the function body. Now that we've had that quick refresher, let's write some more functions!5. Let's practice!
Happy coding!Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.