... lambda.

Lambda functions are just functions but typically very simple ones. It's the fact that makes them really easy to declare that makes them extremely expressive as well and in this series of videos we'd like to demonstrate not just how they work but also why they're nice to reason about.


Note that for this code to run you need to install both numpy and pandas beforehand.

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.normal(0, 1, (10, 2)))
df.columns = ['column_a', 'column_b']
df.loc[lambda d: d['column_b'] > 0]

Note that again here the loc tells us what we're going to be taking a subset of the original dataframe while the lambda function tell us how we're going to select which rows can stay. It can be somewhat complicated to fully appreciate how this works under the hood though. We'll add a chapter on method chains in the future to dive more in depth into this phenomenon.

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider getting the newsletter.