Analyze organic website performance data in Pandas. In this exercise, ingest a 50-row Google Search Console query export (kw1_short.xlsx) containing search queries and visitor click counts. Perform substring filtering with str.contains(), compute aggregated click volumes, and isolate queries by character length extremes.
The practice workbook kw1_short.xlsx contains 50 rows of real-world Google search telemetry with two primary columns: Query (the search query string typed by users) and Clicks (the total organic visitors delivered to the website). Download the sample file below:
Download kw1_short.xlsx (49 Records) ↓
import pandas as pd
# 1. Read Excel workbook
df = pd.read_excel("download/kw1_short.xlsx")
print("Total Records:", len(df))
assert len(df) == 49
# 2. Filter queries containing 'HTML' (case-insensitive)
html_df = df[df["Query"].str.contains("HTML", case=False, na=False)].copy()
print(f"
Queries containing 'HTML': {len(html_df)}")
print(html_df.head())
assert len(html_df) == 15
# 3. Total clicks from HTML queries
total_html_clicks = html_df["Clicks"].sum()
print(f"
Total Clicks for 'HTML' queries: {total_html_clicks}")
assert total_html_clicks == 3528
# 4. Maximum click generating query
max_clicks = html_df["Clicks"].max()
top_query_row = html_df[html_df["Clicks"] == max_clicks]
print(f"
Top Click Query ({max_clicks} clicks):
", top_query_row)
assert max_clicks == 406
assert top_query_row.iloc[0]["Query"] == "marquee speed html"
In search marketing, comparing short-tail versus long-tail queries helps prioritize optimization efforts. Compute the character length of each query using str.len():
# 5 & 6. Query character length extremes
html_df["LENGTH"] = html_df["Query"].str.len()
# Shortest query
min_len = html_df["LENGTH"].min()
shortest_queries = html_df[html_df["LENGTH"] == min_len]
print(f"Shortest Query ({min_len} chars):
", shortest_queries[["Query", "Clicks", "LENGTH"]])
# Longest query
max_len = html_df["LENGTH"].max()
longest_queries = html_df[html_df["LENGTH"] == max_len]
print(f"
Longest Query ({max_len} chars):
", longest_queries[["Query", "Clicks", "LENGTH"]])
assert min_len == 13
assert "html calendar" in shortest_queries["Query"].values
Open in Google Colab View on GitHub
Run all search console query filters, click calculations, and character length analyses interactively in Google Colab.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.