Skip to content

Instantly share code, notes, and snippets.

@john-adeojo
Created March 30, 2023 22:49
Show Gist options
  • Save john-adeojo/536e0f43d278e98ebc216a50a31ce531 to your computer and use it in GitHub Desktop.
Save john-adeojo/536e0f43d278e98ebc216a50a31ce531 to your computer and use it in GitHub Desktop.
# calculate per follower metrics
tweets_df['favorite_count_pf'] = tweets_df['favorite_count']/ tweets_df['follower_count']
tweets_df['retweet_count_pf'] = tweets_df['retweet_count']/ tweets_df['follower_count']
tweets_df['quote_count_pf'] = tweets_df['quote_count']/ tweets_df['follower_count']
tweets_df['reply_count_pf'] = tweets_df['reply_count']/ tweets_df['follower_count']
# normalise metrics
scaler = MinMaxScaler()
scaled_values = scaler.fit_transform(tweets_df[['favorite_count_pf', 'retweet_count_pf', 'quote_count_pf', 'reply_count_pf']])
tweets_df[['favorite_count_pf', 'retweet_count_pf', 'quote_count_pf', 'reply_count_pf']] = scaled_values
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment