Member-only story
How to write an IF Statement with Pandas, Python and Jupyter Notebook
Documentation for writing an IF Statement in a Jupyter notebook with Pandas and Python
Excel users know that IF statements are a powerful way to add logic to their spreadsheet. With Python, IF statements become even more flexible and powerful.
In this tutorial, we’ll create a dataframe from a CSV import, then I’ll show you exactly how to write an IF statement, and how to write that IF statement as a function to apply to one or more columns in your Pandas DataFrame.
We’ll be using a CSV of recipe data scrapped from Reddit’s recipes subreddit.
Our IF statement will scan the recipe content column and add a flag if there are possible allergens that we want to filter out.
This should be fun. Let’s do it.
Table of Contents
- Setting up notebook
- Grabbing data
- Writing a simple IF statement with Python
- Writing a more complex IF statement with Python