Last active
April 29, 2023 19:17
-
-
Save eliasdabbas/c5e90a8ede232b290537fdddedcbb65a to your computer and use it in GitHub Desktop.
Dress SERP heat-map: "dress type styles" and "shop dress type". 40 types. 4 countries: US, UK, CA, AU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import advertools as adv | |
import pandas as pd | |
import plotly | |
import plotly.graph_objects as go | |
pd.options.display.max_columns = None | |
cx = 'YOUR_CSE_ID' | |
key = 'YOUR_GOOGLE_DEV_KEY' | |
# copied from https://www.thetrendspotter.net/types-of-dresses/ | |
dress_keywords = [ | |
'Midi Dress', | |
'Off the Shoulder', | |
'Shift Dress', | |
'Bodycon Dress', | |
'A-Line Dress', | |
'Mini Dress', | |
'Maxi Dress', | |
'Wrap Dress', | |
'Halter Dress', | |
'High-Low Dress', | |
'Sheath Dress', | |
'Peplum Dress', | |
'Sweater Dress', | |
'Pencil Dress', | |
'Shirt Dress', | |
'Slip Dress', | |
'Smock Dress', | |
'Ballgown', | |
'Mermaid Silhouette Dress', | |
'T-shirt Dress', | |
'Tea Length Dress', | |
'Cocktail Dress', | |
'Denim Dress', | |
'Pinafore Dress', | |
'Bardot Dress', | |
'Tube Dress', | |
'Qipao Dress', | |
'Long Sleeve Dress', | |
'Bell-Sleeve Dress', | |
'Strapless Dress', | |
'Blazer Dress', | |
'Empire Waist Dress', | |
'Sun Dress', | |
'Kimono Dress', | |
'One Shoulder Dress', | |
'Handkerchief Hem Dress', | |
'Asymmetrical Dress', | |
'Bandage Dress', | |
'Pouf Dress', | |
'Princess Silhouette Dress', | |
] | |
shop_words = [f'shop {dress.lower()}' for dress in dress_keywords] | |
styles_words = [f'{dress.lower()} styles' for dress in dress_keywords] | |
serp = adv.serp_goog(cx=cx, key=key, gl=['us', 'uk', 'ca', 'au'], q=shop_words + styles_words) | |
# serp_heatmap function definition: | |
# https://gist.github.com/eliasdabbas/9505564080b69fec7198d220c2cacab5 | |
# create any subset as needed, for example: | |
df = (serp_uk_us[serp_uk_us['gl'].eq('uk') & | |
serp_uk_us['searchTerms'].str.contains('shop')] | |
[['rank', 'searchTerms', 'displayLink']])) | |
# OR create a SERP dataset with the columns: "keyword", "rank", and "domain" | |
serp_heatmap(df) | |
# Domain appearances by rank | |
N = 5 | |
(serp_uk_us[serp_uk_us['gl'].eq('us')] | |
.groupby(['rank', 'displayLink']) | |
['displayLink'] | |
.count() | |
.to_frame() | |
.rename(columns={'displayLink': 'count'}) | |
.reset_index() | |
.rename(columns={'displayLink': 'domain'}) | |
.sort_values(['rank', 'count'], ascending=[True, False]) | |
.reset_index(drop=True) | |
.groupby('rank').head(N) | |
.style.bar(subset=['count'], color='darkgray') | |
.hide_index() | |
.set_caption('<h2>Top 5 appearances per SERP rank</h2>')) |
error:
File "", line 68
[['rank', 'searchTerms', 'displayLink']]))
^
SyntaxError: invalid syntax
You need to check your syntax and make sure you haven't made any errors, typos, etc. It's not clear what's happening with this line (before and/or after it).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Raw data: https://bit.ly/3ykpqQV