I'm resetting the question to make it clearer to everyone regarding the DataFrame I have issues with. The DataFrame contains over 100,000 rows with over 10 columns. The important issue I have is filling in any values in the id column that previously matches some value in type column. The values in the id column are not unique. Sometimes both id and type values are NIL.
Note: The order of things should must not be impacted as the records are dated with other columns. There are also no empty cells, all empty cells are filled with "NIL".
GOAL: To replace as many "NIL" as possible in the id column only. I do not care for any "NIL" values in the type column. But everything else must remain the same.
I am assuming this can be done without loops. Thank you for your help! Really appreciate it, strangers!
Current DataFrame
| COL1 | id | type | COL4 | COL5 |
|---|---|---|---|---|
| NIL | 123 | moving | NIL | NIL |
| ... | 123 | lend | ... | ... |
| NIL | 456 | penny | ... | NIL |
| ... | NIL | appendix | NIL | ... |
| ... | 251 | appendix | ... | ... |
| NIL | NIL | lend | ... | NIL |
| ... | 665 | NIL | NIL | ... |
| ... | NIL | NIL | ... | ... |
| ... | 251 | retailer | NIL | NIL |
| NIL | 251 | appendix | ... | NIL |
| NIL | 456 | NIL | ... | NIL |
Expected DataFrame
| COL1 | id | type | COL4 | COL5 |
|---|---|---|---|---|
| NIL | 123 | moving | NIL | NIL |
| ... | 123 | lend | ... | ... |
| NIL | 456 | penny | ... | NIL |
| ... | 251 | appendix | NIL | ... |
| ... | 251 | appendix | ... | ... |
| NIL | 123 | lend | ... | NIL |
| ... | 665 | NIL | NIL | ... |
| ... | NIL | NIL | ... | ... |
| ... | 251 | retailer | NIL | NIL |
| NIL | 251 | appendix | ... | NIL |
| NIL | 456 | NIL | ... | NIL |