Sitemap
Image by Pexels from Pixabay

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

4 min readAug 15, 2023

--

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/'

--

--

David Allen
David Allen

Written by David Allen

Documentation and tutorials on Python, Pandas, Jupyter Notebook, and Data Analysis.

No responses yet