I have this problem with a very large data set which I can finished in Excel in less than a minute but it takes way too long on Python.
Objective: To give each row an ID based on information in column X and Y of the data set.
In Excel:
- Initialize counter to 1
- For each row i:
- If both X = 0 and Y = 0, row ID = counter, followed by counter += 1
- [edited] Else row ID = ID in the previous row.
- Next i
My pd dataframe is large. Doing it in for loop takes more than an hour. I don't know how to vectorise my problem to avoid a for loop.
Hope someone can help me.