Попробуйте:
import pandas as pd
import networkx as nx
df = pd.DataFrame({'Source':[0,1,2,0,16,17,18,0,16,19,1,2],'Target':[1,2,3,3,17,18,19,16,19,3,17,18]})
G = nx.from_pandas_edgelist(df, 'Source', 'Target')
nx.cycles.find_cycle(G)
Вывод:
[(0, 1), (1, 2), (2, 3), (3, 0)]