The Problem
Real data moment
"Show me only the orders over $10" — a completely ordinary question against the real Chipotle data, 4,622 rows deep:
import pandas as pd
df = pd.read_csv("chipotle.tsv", sep="\t")
df["item_price"] = df["item_price"].str.replace("$", "", regex=False).astype(float)
expensive = df[df["item_price"] > 10]
print(len(expensive))
1130
1,130 real orders, out of 4,622, cost more than $10.
The gotcha
Try the same update a different, more tempting-looking way:
df2 = pd.read_csv("chipotle.tsv", sep="\t")
df2["item_price"] = df2["item_price"].str.replace("$", "", regex=False).astype(float)
df2[df2["item_price"] > 40]["item_price"] = 999
print(df2[df2["item_price"] == 999])
ChainedAssignmentError: A value is being set on a copy of a DataFrame or Series through chained assignment.
Such chained assignment never works to update the original DataFrame or Series, because the intermediate object on which we are setting values always behaves as a copy (due to Copy-on-Write).
Try using '.loc[row_indexer, col_indexer] = value' instead, to perform the assignment in a single step.
See the documentation for a more detailed explanation: https://pandas.pydata.org/pandas-docs/stable/user_guide/copy_on_write.html#chained-assignment
Empty DataFrame
Columns: [order_id, quantity, item_name, choice_description, item_price]
Index: []
Look carefully at what actually happened: pandas printed a ChainedAssignmentError — but the script kept running, and the follow-up print shows an empty result. Under pandas 3.0's Copy-on-Write, df2[df2["item_price"] > 40] first builds a temporary filtered copy; assigning into that copy's ["item_price"] afterward modifies only the copy, which is then immediately thrown away. df2 itself was never touched.
This is a warning, not a crash — which makes it more dangerous, not less
ChainedAssignmentError is genuinely misleading by name: by default it's emitted as a warning, not raised as a stopping exception. A script that hits this keeps executing normally, with no traceback, no non-zero exit code — just a printed message easy to miss in a long log, followed by data that silently never changed. "It didn't crash" is not the same as "it worked." After any assignment that matters, verify the change actually landed — don't just check that nothing errored.
df3[df3["quantity"] > 3]["quantity"] = 0 is run on a fresh copy of the Chipotle DataFrame. What actually happens?
This is chained assignment — indexing into df3 once with the boolean mask, then indexing again with ["quantity"] — the exact pattern that triggers Copy-on-Write's ChainedAssignmentError. It prints as a warning (script continues, no exception), and because the assignment happened on a temporary filtered copy, df3's real quantity values never change. The correct rewrite is one step: df3.loc[df3["quantity"] > 3, "quantity"] = 0.