Skip to content

Instantly share code, notes, and snippets.

@FelixChop
Created August 8, 2018 08:25
Show Gist options
  • Select an option

  • Save FelixChop/9ebf314ca6903445c48c6ed5341f84af to your computer and use it in GitHub Desktop.

Select an option

Save FelixChop/9ebf314ca6903445c48c6ed5341f84af to your computer and use it in GitHub Desktop.
# By joining the data with itself, people will have a connection with themselves.
# Remove self connections, to keep only connected people who are different.
d = data_to_merge[~(data_to_merge[column_ID]==data_to_merge[column_ID+"_2"])] \
.dropna()[[column_ID, column_ID+"_2", column_edge]]
# To avoid counting twice the connections (person 1 connected to person 2 and person 2 connected to person 1)
# we force the first ID to be "lower" then ID_2
d.drop(d.loc[d[column_ID+"_2"]<d[column_ID]].index.tolist(), inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment