Member-only story
How to Apply a Function with Two (or more) Arguments in a Pandas DataFrame
Documentation for applying a function with one or 2+ arguments in a Pandas Dataframe, using Pandas, Python, and Jupyter Notebook. Data from the Fantasy Premier League API
In this short tutorial, I’ll show you exactly how to apply a function that will accept both one argument and multiple arguments in a Pandas Dataframe.
The approaches are somewhat different, using the .apply() method directly on a column to apply a single-parameter function, and then using a lambda function to pass multiple parameters to a slightly more complex function.
If you are into Fantasy Premier League, or soccer/football, you’re going to like this one.
Let’s do it.
Step 0: Grab some data
For this tutorial, we’ll ask the Fantasy Premier League API for some data.
First, the imports:
import pandas as pd
import requests
import numpy as np
Then set the endpoint to a variable:
url = 'https://fantasy.premierleague.com/api/bootstrap-static/'