Skip to content

Instantly share code, notes, and snippets.

@itsderek23
Created July 5, 2019 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsderek23/41cd10943201e7b664619c6cd15f409d to your computer and use it in GitHub Desktop.
Save itsderek23/41cd10943201e7b664619c6cd15f409d to your computer and use it in GitHub Desktop.
SERP Analysis - Clicks, impressions, position, and CTR by query
df_by_query = (df
.groupby("query")
.agg({"clicks": "sum", "impressions": "sum", "position": "mean"})
.sort_values("clicks",ascending=False))
df_by_query["ctr"] = (df_by_query.clicks / df_by_query.impressions)*100
df_by_query.head(5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment