Skip to content

Instantly share code, notes, and snippets.

View benlindsay's full-sized avatar

Ben Lindsay benlindsay

View GitHub Profile
@alexkyllo
alexkyllo / debug_pandas.py
Last active January 16, 2022 18:38
Debugging in the middle of a pandas method chain
"""Example of how to open a debugger anywhere in the middle of a pandas method chain."""
import numpy as np
import seaborn as sns
from IPython.core.debugger import Pdb
df = sns.load_dataset("iris")
df = (
df.assign(sepal_ratio=lambda x: np.divide(x["sepal_width"], x["sepal_length"]))
.pipe(lambda x: Pdb().set_trace()) # Opens the debugger, the dataframe is assigned to `x`