Skip to content

Instantly share code, notes, and snippets.

@khuyentran1401
Last active October 31, 2021 19:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save khuyentran1401/e6361d1e3f25a2a9c52c0507af322d04 to your computer and use it in GitHub Desktop.
Save khuyentran1401/e6361d1e3f25a2a9c52c0507af322d04 to your computer and use it in GitHub Desktop.
def get_friends_df(data: pd.DataFrame):
"""Get the number of friends for all people in the network"""
all_people = list(set(data["person1"]).union(set(data["person2"])))
num_friends = [
{
"person_id": person_id,
"num_friends": get_num_friends(data, person_id),
"avg_friends_of_friends": round(
get_average_friends_of_a_person_friends(data, person_id), 2
),
}
for person_id in all_people
]
return pd.DataFrame(num_friends)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment