SlideShare a Scribd company logo
THE PYTHON CHEAT SHEET FOR
THE BUSY MARKETER
H A M L E T B A T I S T A
#INBOUND2020
Google Colaboratory
feature walkthrough
GOOGLE COLAB
Preparing your Python
notebook environment
SETUP
Publish your analysis to
Google Sheets directly
from Python
EXPORTING TO SHEETS
Convert your data
analysis into simpler to
understand formats
DATA TRANSFORMATION
Process API output to
extract insights
JSON PARSING
Run automated analysis
using Google
Lighthouse
API CALLING
AGENDA
T H E P Y T H O N C H E A T S H E E T F O R T H E
B U S Y M A R K E T E R
@hamletbatista
Fetch content from the
web
WEB SCRAPING
Basic data types,
Containers, Functions,
Classes
PYTHON BASICS
INTRODUCTION
P Y T H O N S O U R C E D D A T A S T U D I E S
Published April 7, 2020
PAGE SPEED SCORES OF EVERY
SHOPIFY THEME
Published June 23, 2020
ACCESSING ‘CORE WEB VITALS’ OF
EVERY SHOPIFY THEME
Our work in this presentation
AN SEO ASSESSMENT OF EVERY
SHOPIFY THEME
#INBOUND2020
https://bit.ly/31JXHJ1https://bit.ly/38tEixp https://bit.ly/31JXHJ1
@hamletbatista
We will run Google
Lighthouse SEO analysis
feature under mobile
emulation
GOOGLE LIGHTHOUSE
We will scrape the demo
sites of every theme
SHOPIFY THEME STORE
We will use a handy cheat
sheet spread over multiple
Python notebooks
CHEAT SHEET
PYTHON SOURCED
DATA STUDY
A M O B I L E S E O A S S E S S M E N T O F E V E R Y S H O P I F Y T H E M E
#INBOUND2020 @hamletbatista
POWERED BY GOOGLE
LIGHTHOUSE
A M O B I L E S E O A S S E S S M E N T O F E V E R Y S H O P I F Y T H E M E
#INBOUND2020 @hamletbatista
We will run Google
Lighthouse SEO analysis
feature under mobile
emulation
GOOGLE LIGHTHOUSE
We will scrape the demo
sites of every theme
SHOPIFY THEME STORE
We will use a handy cheat
sheet spread over multiple
Python notebooks
CHEAT SHEET
SETUP
1
Create a new Python notebook directly from
Google Drive
#INBOUND2020
U S I N G G O O G L E C O L A B O R A T O R Y
Getting Started:
• Overview of Colaboratory Features
@hamletbatista
GOOGLE COLAB
FEATURES
T U R N N O T E B O O K S I N T O P R O G R A M S
2
Google Colab’s includes many useful
features that simplify data acquisition,
preparation and analysis.
#INBOUND2020
Most common form fields:
input1 = “value” #@param {type:”string”}
input2 = 10 #@param {type:”integer”}
input3 = “2020-09-22” #@param {type:”date”}
@hamletbatista
PYTHON
BASICS
3
Google Colab requires Python code. Let’s
let’s review some of the basic constructs.
#INBOUND2020
T H E L A N G U A G E O F D A T A S C I E N C E
@hamletbatista
Python learning resources:
• An Introduction to Python for Technical SEO
• An Introduction to Python for SEO Pros Using Spreadsheets
• How to Use Python to Analyze SEO Data: A Reference Guide
4
#INBOUND2020 @hamletbatista
WEB
SCRAPING
In our example, we will scrape the Shopify
Theme’s Store for theme names and demo
site URLs
F E T C H C O N T E N T F R O M T H E W E B
Example Scrapy spider changes:
• start_urls
• “Next page” CSS selector
• Elements to extract (theme name and link)
Learn more:
• Scrapy.org
API CALLING
5
In our example, we will call the Page Speed
Insights API to get SEO assessment metrics
and recommendations
#INBOUND2020
R U N A U T O M A T E D A N A L Y S I S
Most common request call:
r = requests.get(api_url, headers={'Accept': 'application/json'})
if r.status_code == 200:
return r.json()
Learn more:
• Requests: HTTP for Humans
@hamletbatista
JSON PARSING
P R O C E S S I N G A P I R E S P O N S E S
6
Complex JSON API responses can be a
pain to process. We will use JSONPath to
drastically simplify this.
#INBOUND2020
Most common JSONPath recipe:
json_path = “$.lighthouseResult.categories.seo.score”
jsonpath_tree = parse(json_path)
value = [match.value for match in jsonpath_tree.find(data)]
Learn more:
JSON JSONPath Tutorial
@hamletbatista
DATA
TRANSFORMATION
7
In our example, we will use Python pandas
to reorganize our study in a way that is easy
to interpret
#INBOUND2020
D A T A I S R A R E L Y I N T H E B E S T F O R M A T
Converting a list of dictionaries to Pandas Data Frame:
import pandas as pd
new_format = [{“column1_name”: “value”},{“column2_name”: “value”} ]
df = pd.DataFrame(new_format)
Learn more:
• 10 minutes to pandas
@hamletbatista
EXPORTING TO
SHEETS
G O O G L E S H E E T S I S S I M P L E R
8
Once we produce our data in Python we
can transfer it directly to Google Sheets
for further analysis and reporting
#INBOUND2020
Transferring a Pandas Data Frame to a Google Sheet :
spread = Spread("INBOUND2020", creds=creds)
spread.df_to_sheet(df, index=False, sheet="Themes SEO audits",
start='A1', replace=True)
Learn more:
• Examples of gspread Usage
• Introduction to gspread_pandas (video)
@hamletbatista
LOCATION
33 Wood Ave South
Suite 600
Iselin, NJ 08830
USA
PHONE
CONTACT US
+1 866.882.2983
https://www.ranksense.com
#INBOUND2020
ABOUT
RANKSENSE
A U T O M A T E A N D R U N S E O E X P E R I M E N T S
F R O M G O O G L E S H E E T S
@RankSense

More Related Content

PPTX
Keyword Research and Topic Modeling in a Semantic Web
PPTX
How to Automatically Subcategorise Your Website Automatically With Python
PPTX
The Reason Behind Semantic SEO: Why does Google Avoid the Word PageRank?
PPTX
Semantic seo and the evolution of queries
PPTX
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
PDF
40 Deep #SEO Insights for 2023
PPTX
Semantic Content Networks - Ranking Websites on Google with Semantic SEO
PDF
Semantic Search Engine: Semantic Search and Query Parsing with Phrases and En...
Keyword Research and Topic Modeling in a Semantic Web
How to Automatically Subcategorise Your Website Automatically With Python
The Reason Behind Semantic SEO: Why does Google Avoid the Word PageRank?
Semantic seo and the evolution of queries
Search Query Processing: The Secret Life of Queries, Parsing, Rewriting & SEO
40 Deep #SEO Insights for 2023
Semantic Content Networks - Ranking Websites on Google with Semantic SEO
Semantic Search Engine: Semantic Search and Query Parsing with Phrases and En...

What's hot (20)

PDF
How to Incorporate ML in your SERP Analysis, Lazarina Stoy -BrightonSEO Oct, ...
PDF
Antifragility in Digital Marketing
PDF
Automating Google Lighthouse
PDF
AI-powered Semantic SEO by Koray GUBUR
PPTX
Lexical Semantics, Semantic Similarity and Relevance for SEO
PDF
Quality Content at Scale Through Automated Text Summarization of UGC
PPTX
Opinion-based Article Ranking for Information Retrieval Systems: Factoids and...
PPTX
Semantic search
PDF
The Ultimate Google Indexing Session
PPT
SEO & Patents Vrtualcon v. 3.0
PDF
Building a Search Intent-Driven Website Architecture (SEO Mastery Summit 2022...
PPTX
Entity seo
PPTX
How Search Works
PDF
BrightonSEO April 2023 Similar AI: Automation recipes for SEO success
PPTX
BrightonSEO March 2021 | Dan Taylor, Image Entity Tags
PPTX
How to Build a Semantic Search System
PDF
Coronavirus and Future of SEO: Digital Marketing and Remote Culture
PDF
A beginner's guide to machine learning for SEOs - WTSFest 2022
PPTX
Slawski New Approaches for Structured Data:Evolution of Question Answering
PPTX
Semantic Web, Knowledge Graph, and Other Changes to SERPS – A Google Semantic...
How to Incorporate ML in your SERP Analysis, Lazarina Stoy -BrightonSEO Oct, ...
Antifragility in Digital Marketing
Automating Google Lighthouse
AI-powered Semantic SEO by Koray GUBUR
Lexical Semantics, Semantic Similarity and Relevance for SEO
Quality Content at Scale Through Automated Text Summarization of UGC
Opinion-based Article Ranking for Information Retrieval Systems: Factoids and...
Semantic search
The Ultimate Google Indexing Session
SEO & Patents Vrtualcon v. 3.0
Building a Search Intent-Driven Website Architecture (SEO Mastery Summit 2022...
Entity seo
How Search Works
BrightonSEO April 2023 Similar AI: Automation recipes for SEO success
BrightonSEO March 2021 | Dan Taylor, Image Entity Tags
How to Build a Semantic Search System
Coronavirus and Future of SEO: Digital Marketing and Remote Culture
A beginner's guide to machine learning for SEOs - WTSFest 2022
Slawski New Approaches for Structured Data:Evolution of Question Answering
Semantic Web, Knowledge Graph, and Other Changes to SERPS – A Google Semantic...
Ad

Similar to The Python Cheat Sheet for the Busy Marketer (20)

PPT
Lessons Learned - Building YDN
PDF
From Knowledge Graphs to AI-powered SEO: Using taxonomies, schemas and knowle...
PPTX
Web programming using python frameworks.
PDF
AI Deeplearning Programming
PPT
Google Opening up to Developers - From 2 to 55 APIs in 3 years
PDF
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
PDF
Integrating the OpenAI API in Your Coldfusion Apps.pdf
PPTX
Developer Grade SEO
PDF
Building Beautiful REST APIs with ASP.NET Core
PDF
Solving performance issues in Django ORM
PDF
Resume analyst
PDF
Natural Language Processing sample code by Aiden
PPT
Introduction to python scrapping
PDF
Introduction to python
PDF
Velocity Conference - What do cats and APIs have in common? They are both awe...
ODP
Intro To Spring Python
PDF
API Integration in Web Application
PDF
How fiddling with GraphQL enhanced communications between our back and front ...
PPT
Yahoo! BOSS in Bucharest
PDF
the Spring Update from JavaOne 2013
Lessons Learned - Building YDN
From Knowledge Graphs to AI-powered SEO: Using taxonomies, schemas and knowle...
Web programming using python frameworks.
AI Deeplearning Programming
Google Opening up to Developers - From 2 to 55 APIs in 3 years
apidays Paris 2022 - France Televisions : How we leverage API Platform for ou...
Integrating the OpenAI API in Your Coldfusion Apps.pdf
Developer Grade SEO
Building Beautiful REST APIs with ASP.NET Core
Solving performance issues in Django ORM
Resume analyst
Natural Language Processing sample code by Aiden
Introduction to python scrapping
Introduction to python
Velocity Conference - What do cats and APIs have in common? They are both awe...
Intro To Spring Python
API Integration in Web Application
How fiddling with GraphQL enhanced communications between our back and front ...
Yahoo! BOSS in Bucharest
the Spring Update from JavaOne 2013
Ad

More from Hamlet Batista (20)

PDF
A Deep Dive Into SEO Tactics For Modern Javascript Frameworks
PDF
Automated Duplicate Content Consolidation with Google Cloud Functions
PDF
SEO Meets Automation
PDF
Creando una Sección de FAQS y su Marcado de Datos Estructurados en 30 Minutos
PPTX
Doing More with Less: Automated, High-Quality Content Generation
PPTX
How to scale SEO work NOBODY wants to do (including your competitors) to rapi...
PPTX
Agile SEO: Faster SEO Results
PPTX
Scaling Keyword Research to Find Content Gaps
PPTX
Query Classification on Steroids with BERT
PPTX
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
PPTX
Python for Data-driven Storytelling
PPTX
Scaling automated quality text generation for enterprise sites
PPTX
The New Renaissance of JavaScript
PPTX
Data and Evidence-driven SEO
PPTX
Python for SEO
PPTX
Advanced Data-Driven SEO
PPTX
Technical SEO "Overoptimization"
PPTX
Why Pay for Performance When You Can Lead the World To Your Door for Free?
PPTX
Gettin' It Up And Keepin' It Up in Google
PPTX
Batista, Hamlet, Beyond The Usual Link Building
A Deep Dive Into SEO Tactics For Modern Javascript Frameworks
Automated Duplicate Content Consolidation with Google Cloud Functions
SEO Meets Automation
Creando una Sección de FAQS y su Marcado de Datos Estructurados en 30 Minutos
Doing More with Less: Automated, High-Quality Content Generation
How to scale SEO work NOBODY wants to do (including your competitors) to rapi...
Agile SEO: Faster SEO Results
Scaling Keyword Research to Find Content Gaps
Query Classification on Steroids with BERT
Solving Complex JavaScript Issues and Leveraging Semantic HTML5
Python for Data-driven Storytelling
Scaling automated quality text generation for enterprise sites
The New Renaissance of JavaScript
Data and Evidence-driven SEO
Python for SEO
Advanced Data-Driven SEO
Technical SEO "Overoptimization"
Why Pay for Performance When You Can Lead the World To Your Door for Free?
Gettin' It Up And Keepin' It Up in Google
Batista, Hamlet, Beyond The Usual Link Building

Recently uploaded (20)

PDF
How a Travel Company Can Implement Content Marketing
PDF
Fly Emirates SEO case study by Rakesh pathak.pdf
PDF
Unit 1 -2 THE 4 As of RURAL MARKETING MIX.pdf
PDF
Digital Marketing in the Age of AI: What CEOs Need to Know - Jennifer Apy, Ch...
PDF
Digital Marketing Agency in Thrissur with Proven Strategies for Local Growth
PDF
Mastering the Art of the Prompt - Brantley Smith, HomePro Marketing
PPTX
Assignment 2 Task 1 - How Consumers Use Technology and Its Impact on Their Lives
PPTX
Solomon_Chapter 6_The Self: Mind, Gender, and Body.pptx
DOCX
AL-ahly Sabbour un official strategic plan.docx
PDF
exceptionalinsights.group visitor traffic statistics 08-08-25
PPTX
Final Project parkville.............pptx
PDF
PDF
Proven AI Visibility: From SEO Strategy To GEO Tactics
PDF
Ramjilal Ramsaroop || Trending Branding
PPTX
UNIT 3 - 5 INDUSTRIAL PRICING.ppt x
PPTX
Mastering eCommerce SEO: Strategies to Boost Traffic and Maximize Conversions
PPTX
Amazon - STRATEGIC.......................pptx
PDF
EVOLUTION OF RURAL MARKETING IN INDIAN CIVILIZATION
PDF
AFCAT Syllabus 2026 Guide by Best Defence Academy in Lucknow.pdf
PPTX
Kimberly Crossland Storytelling Marketing Class 5stars.pptx
How a Travel Company Can Implement Content Marketing
Fly Emirates SEO case study by Rakesh pathak.pdf
Unit 1 -2 THE 4 As of RURAL MARKETING MIX.pdf
Digital Marketing in the Age of AI: What CEOs Need to Know - Jennifer Apy, Ch...
Digital Marketing Agency in Thrissur with Proven Strategies for Local Growth
Mastering the Art of the Prompt - Brantley Smith, HomePro Marketing
Assignment 2 Task 1 - How Consumers Use Technology and Its Impact on Their Lives
Solomon_Chapter 6_The Self: Mind, Gender, and Body.pptx
AL-ahly Sabbour un official strategic plan.docx
exceptionalinsights.group visitor traffic statistics 08-08-25
Final Project parkville.............pptx
Proven AI Visibility: From SEO Strategy To GEO Tactics
Ramjilal Ramsaroop || Trending Branding
UNIT 3 - 5 INDUSTRIAL PRICING.ppt x
Mastering eCommerce SEO: Strategies to Boost Traffic and Maximize Conversions
Amazon - STRATEGIC.......................pptx
EVOLUTION OF RURAL MARKETING IN INDIAN CIVILIZATION
AFCAT Syllabus 2026 Guide by Best Defence Academy in Lucknow.pdf
Kimberly Crossland Storytelling Marketing Class 5stars.pptx

The Python Cheat Sheet for the Busy Marketer

  • 1. THE PYTHON CHEAT SHEET FOR THE BUSY MARKETER H A M L E T B A T I S T A #INBOUND2020
  • 2. Google Colaboratory feature walkthrough GOOGLE COLAB Preparing your Python notebook environment SETUP Publish your analysis to Google Sheets directly from Python EXPORTING TO SHEETS Convert your data analysis into simpler to understand formats DATA TRANSFORMATION Process API output to extract insights JSON PARSING Run automated analysis using Google Lighthouse API CALLING AGENDA T H E P Y T H O N C H E A T S H E E T F O R T H E B U S Y M A R K E T E R @hamletbatista Fetch content from the web WEB SCRAPING Basic data types, Containers, Functions, Classes PYTHON BASICS
  • 3. INTRODUCTION P Y T H O N S O U R C E D D A T A S T U D I E S Published April 7, 2020 PAGE SPEED SCORES OF EVERY SHOPIFY THEME Published June 23, 2020 ACCESSING ‘CORE WEB VITALS’ OF EVERY SHOPIFY THEME Our work in this presentation AN SEO ASSESSMENT OF EVERY SHOPIFY THEME #INBOUND2020 https://bit.ly/31JXHJ1https://bit.ly/38tEixp https://bit.ly/31JXHJ1 @hamletbatista
  • 4. We will run Google Lighthouse SEO analysis feature under mobile emulation GOOGLE LIGHTHOUSE We will scrape the demo sites of every theme SHOPIFY THEME STORE We will use a handy cheat sheet spread over multiple Python notebooks CHEAT SHEET PYTHON SOURCED DATA STUDY A M O B I L E S E O A S S E S S M E N T O F E V E R Y S H O P I F Y T H E M E #INBOUND2020 @hamletbatista
  • 5. POWERED BY GOOGLE LIGHTHOUSE A M O B I L E S E O A S S E S S M E N T O F E V E R Y S H O P I F Y T H E M E #INBOUND2020 @hamletbatista We will run Google Lighthouse SEO analysis feature under mobile emulation GOOGLE LIGHTHOUSE We will scrape the demo sites of every theme SHOPIFY THEME STORE We will use a handy cheat sheet spread over multiple Python notebooks CHEAT SHEET
  • 6. SETUP 1 Create a new Python notebook directly from Google Drive #INBOUND2020 U S I N G G O O G L E C O L A B O R A T O R Y Getting Started: • Overview of Colaboratory Features @hamletbatista
  • 7. GOOGLE COLAB FEATURES T U R N N O T E B O O K S I N T O P R O G R A M S 2 Google Colab’s includes many useful features that simplify data acquisition, preparation and analysis. #INBOUND2020 Most common form fields: input1 = “value” #@param {type:”string”} input2 = 10 #@param {type:”integer”} input3 = “2020-09-22” #@param {type:”date”} @hamletbatista
  • 8. PYTHON BASICS 3 Google Colab requires Python code. Let’s let’s review some of the basic constructs. #INBOUND2020 T H E L A N G U A G E O F D A T A S C I E N C E @hamletbatista Python learning resources: • An Introduction to Python for Technical SEO • An Introduction to Python for SEO Pros Using Spreadsheets • How to Use Python to Analyze SEO Data: A Reference Guide
  • 9. 4 #INBOUND2020 @hamletbatista WEB SCRAPING In our example, we will scrape the Shopify Theme’s Store for theme names and demo site URLs F E T C H C O N T E N T F R O M T H E W E B Example Scrapy spider changes: • start_urls • “Next page” CSS selector • Elements to extract (theme name and link) Learn more: • Scrapy.org
  • 10. API CALLING 5 In our example, we will call the Page Speed Insights API to get SEO assessment metrics and recommendations #INBOUND2020 R U N A U T O M A T E D A N A L Y S I S Most common request call: r = requests.get(api_url, headers={'Accept': 'application/json'}) if r.status_code == 200: return r.json() Learn more: • Requests: HTTP for Humans @hamletbatista
  • 11. JSON PARSING P R O C E S S I N G A P I R E S P O N S E S 6 Complex JSON API responses can be a pain to process. We will use JSONPath to drastically simplify this. #INBOUND2020 Most common JSONPath recipe: json_path = “$.lighthouseResult.categories.seo.score” jsonpath_tree = parse(json_path) value = [match.value for match in jsonpath_tree.find(data)] Learn more: JSON JSONPath Tutorial @hamletbatista
  • 12. DATA TRANSFORMATION 7 In our example, we will use Python pandas to reorganize our study in a way that is easy to interpret #INBOUND2020 D A T A I S R A R E L Y I N T H E B E S T F O R M A T Converting a list of dictionaries to Pandas Data Frame: import pandas as pd new_format = [{“column1_name”: “value”},{“column2_name”: “value”} ] df = pd.DataFrame(new_format) Learn more: • 10 minutes to pandas @hamletbatista
  • 13. EXPORTING TO SHEETS G O O G L E S H E E T S I S S I M P L E R 8 Once we produce our data in Python we can transfer it directly to Google Sheets for further analysis and reporting #INBOUND2020 Transferring a Pandas Data Frame to a Google Sheet : spread = Spread("INBOUND2020", creds=creds) spread.df_to_sheet(df, index=False, sheet="Themes SEO audits", start='A1', replace=True) Learn more: • Examples of gspread Usage • Introduction to gspread_pandas (video) @hamletbatista
  • 14. LOCATION 33 Wood Ave South Suite 600 Iselin, NJ 08830 USA PHONE CONTACT US +1 866.882.2983 https://www.ranksense.com #INBOUND2020 ABOUT RANKSENSE A U T O M A T E A N D R U N S E O E X P E R I M E N T S F R O M G O O G L E S H E E T S @RankSense