Python for SEOMarch 25, 2026
How to categorize 10,000 keywords by Intent using Python in 30 seconds
Master AI Automation 2026 and Generative Engine Optimization. Automate keyword intent classification with Python for AI Automation 2026 and Generative Engine Optimization, saving hours of manual data entry.
Search intent is the single most important signal in modern SEO. Google explicitly assigns keywords to one of four intent buckets — and if your content doesn't match the intent, you simply won't rank, no matter how technically perfect your page is.
The problem? Manually labeling a list of 10,000 keywords is a nightmare. Spreadsheet formulas break. Outsourcing it is expensive. SaaS tools charge per-credit.
This recipe uses Python to do it in under 30 seconds, completely for free, on your machine — and you keep full control of the logic.
The Four Intent Categories
Before we write a single line of code, understand what we're classifying:
| Intent | Definition | Example Keywords |
|---|---|---|
| Informational | User wants to learn something | "what is keyword clustering", "how does SEO work" |
| Navigational | User is looking for a specific brand/page | "ahrefs login", "semrush pricing page" |
| Commercial | User is comparing options before buying | "best SEO tools 2026", "ahrefs vs semrush" |
| Transactional | User is ready to buy or take action | "buy ahrefs subscription", "semrush discount code" |
Our Python script will automatically assign one of these four tags to every keyword in your CSV.
What You'll Need
The only dependency is
pandas for reading and writing CSV files. No LLM API, no cloud, no account:That's it. Python's standard library handles the rest.
Part 1: The Basic Rule-Based Classifier
This is the foundation. Start with this script — it works on any keyword list out of the box.
Save it as
intent_classifier.py:How to Use It
Step 1: Export your keyword list from Ahrefs, Semrush, or Google Search Console. The file needs at least one column — your keywords.
Step 2: Rename the column header to
keyword (or change keyword_col in the script).Step 3: Run it:
You'll see output like this directly in the terminal:
Step 4: Open
intent_output.csv. Every row now has an intent column. Filter by Transactional and you instantly know which keywords to prioritize for your product pages.Part 2: Segment by Volume & Intent Together
Knowing intent is just the first step. The real power comes from combining it with search volume to prioritize what to work on first.
If your CSV already has a
volume column (it will if you export from Ahrefs), extend the script with this block:Your output now gives you a fully prioritized content roadmap — not just intent tags.
Part 3: Export a Separate File Per Intent
For large teams, you often need to hand off specific intent groups to different people (e.g., editorial team gets Informational; performance team gets Transactional). Add this after the main output:
Then call it after your main processing:
Part 4: Customizing for Your Niche
The script above is generic. To make it dramatically more accurate, add niche-specific signals to the lists at the top of the file.
Example: SaaS tooling niche:
Example: E-commerce niche:
The more targeted your signal lists, the closer to 95%+ accuracy you'll get — without paying for a single API call.
Common Mistakes to Avoid
Mistake 1: Relying on this for head terms only. This script is especially powerful for long-tail keywords (4+ words) where intent is crystal clear. For 1–2 word head terms, manual review is still worth it.
Mistake 2: Forgetting to lowercase. The script already handles this with.lower().strip(), but don't remove it when editing.
Mistake 3: Not customizing the signal lists. The default lists are a starting point. Ten minutes of customization will dramatically improve accuracy.
The Meta Effect
By automating keyword intent classification, you enable a compounding productivity advantage:
- You can now run this daily against new keyword data from GSC exports — zero effort.
- Every keyword you rank for is labeled, so you know exactly what intent Google associates your pages with.
- You can A/B test content strategy by checking if switching a page's angle (e.g., from Informational to Commercial) correlates with rank changes.
In future recipes, we'll pipe this output directly into an LLM API to auto-generate content briefs grouped by intent — turning a 10-hour content strategy session into a 2-minute script run.