Method Chaining
noun
say it: “METH-ud CHAYN-ing” /ˈmɛθəd ˈtʃeɪnɪŋ/
Writing several steps on a table as one expression, each step working on the result of the one before it, so the code reads like a recipe.
What is method chaining in pandas?
Method chaining writes several steps as one expression, one method per line, each working on the table the step before it handed back. It reads top to bottom like a recipe and leaves no half-finished tables behind; wrap the chain in parentheses so it can span lines.
clean = (
raw
.rename(columns={"Temp (F)": "temp_f"})
.drop_duplicates()
.sort_values("timestamp")
)
In a sentence
- “Each line of the method chaining works on the table the line above handed back.”
- “With method chaining, the whole cleaning fit in one readable block.”
Level: Journeyman · More Python terms at this level
Updated