I have a dataframe with 2 columns : id , antecedent_id I would like a code to reorder the dataframe in the right order using antecedent_id. The first id is the one with antecedent_id empty
Dataframe example:
| id | antecedent_id |
|---|---|
| id1 | id2 |
| id4 | id7 |
| id6 | id3 |
| id7 | |
| id3 | id4 |
| id2 | id6 |
| id5 | id1 |
The dataframe reordered should be like this:
| id | antecedent_id |
|---|---|
| id7 | |
| id4 | id7 |
| id3 | id4 |
| id6 | id3 |
| id2 | id6 |
| id1 | id2 |
| id5 | id1 |
I would like to find the fastest code to do that as I have a huge number of rows
Thanks you so much for your help !