my goal is to find if the following df has a 'circulation'
given:
df = pd.DataFrame({'From':['USA','UK','France','Italy','Russia','china','Japan','Australia','Russia','Italy'],
'to':['UK','France','Italy','Russia','china','Australia','New Zealand','Japan','USA','France']})
df
and if I graph it, it would look like this (eventually, note that the order on the df is different):
USA-->UK-->France-->Italy-->Russia-->China-->Australia-->Japan-->Australia
| |
| |
France USA
The point is this: You cannot go backward, so Italy cannot go to France and Russia cannot go to USA.
Note: From can have multiple Tos
How can I find it in pandas so the end result would look like this:

I can solve it without pandas (I get df.to_dict('records') and then iterate to find the circulation and then go back to pandas) but I wish to stay on pandas.

