Great question — answering as the UphillTech team:
EDIT: I originally put in two solutions, but when I tested the code more robustly, the first one doesn't work. I think that collecting the column into a dataframe actually makes it impossible to do what you need to do here. You can only pull the current index out as an expression (Expr), and I think that means you're stuck doing everything with expressions, so no collecting. (Also I fixed a small typo in the working solution below. I think I pasted it in wrong.) The current index can be found in p.col("index"), since you put it there. You'll have to make sure it's there and starts at 1 when you read in from the CSV, but I'm assuming you've already done that. The best strat I could think of...
Full answer by concerned_citizen: https://stackoverflow.stackexchange.com/a/80014517 (CC BY-SA 4.0).
Need it done for your business? UphillTech.