How do I avoid cycles across two columns within a DataFrame to render a Sankey diagram with Google Charts?
<p>I have a DataFrame with source and destination IPs, and bytes,</p>

<pre><code>[ 1.2.3.4, 8.8.8.8, 123456 ]
...
[ 8.8.8.8, 1.2.3.4, 1234 ]
</code></pre>

<p>My problem is that I am using this DataFrame for a <a href="https://developers.google.com/chart/interactive/docs/gallery/sankey" rel="nofollow">JS visualization</a> which breaks if there is such a cycle. Like between 1.2.3.4 and 8.8.8.8.</p>

<blockquote>
  <p>Note: Avoid cycles in your data: if A links to itself, or links to B
  which links to C which links to A, your chart will not render</p>
</blockquote>

<p>Is there a way to make sure that I remain uni-directional in the relationship? So in case 8.8.8.8 links back to 1.2.3.4 - and creates a cycle - I'd either skip it or swap the values. I am not sure if swapping is an option with Pandas.</p>

<p>I got myself a quick workaround by limiting it to the top 10 talkers, where a cycle is less likely. But it's incomplete of course.</p>

<pre><code>vis_data += str(netflow_df.groupby(("dip","sip","bytes"), as_index=False).sum()
                .sort_values(by="bytes", ascending=False)
                .head(10)[["sip", "dip", "bytes"]]
                .values.tolist()
               )
</code></pre>

<p>Without having any extra information would something like this be sufficient? :</p>

<pre><code>for index in range(df1):
    if df1[a] == df2[b]:

        if df1[b]  == df2[a]:
             df1.drop(df1.index[index])
    pass
</code></pre>

python pandas google-visualization