How would you rewrite a row-by-row pandas transformation, and what is SettingWithCopyWarning telling you?
Push the work into a whole-column operation so the interpreter is entered once instead of once per row, replace chained indexing with a single .loc assignment, and move to DuckDB, Polars or a cluster once the frame plus its intermediate copies stop fitting in memory.