Skip to content

Instantly share code, notes, and snippets.

@vessaldaneshvar
Created October 15, 2020 17:59
Show Gist options
  • Save vessaldaneshvar/0ad8c0ec8f4899189408d1cc97b6cc6a to your computer and use it in GitHub Desktop.
Save vessaldaneshvar/0ad8c0ec8f4899189408d1cc97b6cc6a to your computer and use it in GitHub Desktop.
Weight relations
df_relations = df_relations.drop(columns=df_relations.columns[0])
def weight_graph(df):
sum_weight = 0
for row in df["relation_type"]:
if row == "RETWEET":
sum_weight += 2
elif row == "RETWEET_QOUTE":
sum_weight += 1
elif row == "MENTIONS":
sum_weight += 4
elif row == "FOLLOWS":
sum_weight += 20
elif row == "REPLY":
sum_weight += 3
elif row == "QOUTE":
sum_weight += 5
return sum_weight
df_group_relation = df_relations.groupby(["source","destination"]).apply(weight_graph)
df_group_relation = df_group_relation.reset_index(name="weight")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment