Forecasting Seasonal Keyword Traffic with Python Script
-
A few weeks back, I went to a Distilled meetup here in NYC. SEER Interactive's Mark Lavoritano did some cool slides on the seasonality of keywords. Basically, his presentation made the point that you should not only think about which keywords you want to rank for but also WHEN they are most valuable.
This made me think...we have a lot of moving parts to our marketing efforts. Emails with interchangeable modules, a homepage with interchangeable links, and other dynamic elements for which we have to decide what themes we want to market for the week. Babies or bikes? Kitchen Gadgets or Wine Glasses?
Google Insights for Search is a great tool which allows you to look at keyword traffic year over year. However, for many of the keywords (like the ones mentioned above), on a multi-year timeframe, it can be tough to sift out the specific weeks in which traffic repeatedly peaks year after year. What I really wanted to see was the last 5 years laid on top of each other to find the common peaks. Even better, if I could map 5 years of keyword data to a single row in a spreadsheet and then use conditional formatting to create a colorscale, I could create a sweet forecasting calendar with several keywords and use this to choose the best timing for various marketing campaigns. Here's a link to a screenshot of the calendar I created: forecasting calendar
I could have done this in excel, but I've been wanting to try out Python for a while now and decided this was a great time to do it. After some reasearch, I figured out how to import a csv into python and the rest was done with for loops and lists, which is fairly basic python. I've pasted my code below. In a nutshell, the program runs through all 5 years of traffic data and increments a count in a list whenever it sees a peak (according to a threshold called "peakInterestValue" that you set in the code). The output is a list of 52 numbers [0-5] (representing 52 weeks over 5 years). If the value is a 5, it means that all 5 years showed a peak in traffic at that week. If it's a 4, then 4 (out of 5) years showed a peak that week, etc...you can then copy/paste this to a row in an excel sheet with all your keywords, apply a color scale w/ conditional formatting, and boom! you've got a forecasting calendar.
This code works on the exact file that Google insights exports so you don't need to format it at all. It's ready to rock.
If you want to see the code formatted and cleaned up, check it out here. If you want to see a hot mess, I've also pasted the code below. You can drop it right into a .py file and run it off a cmd prompt but you'll need to install python first:
http://www.python.org has installation info and great tutorials as well.
import csv """reads a file from google insights""" """Open the last 5 years of data from Google Insights""" anniversarygiftFile2007 = csv.reader(open("anniversarygift2007.csv","r"))anniversarygiftFile2008 = csv.reader(open("anniversarygift2008.csv","r"))anniversarygiftFile2009 = csv.reader(open("anniversarygift2009.csv","r"))anniversarygiftFile2010 = csv.reader(open("anniversarygift2010.csv","r"))anniversarygiftFile2011 = csv.reader(open("anniversarygift2011.csv","r"))
"""Combines the data into a list"""
anniversarygiftFile = [anniversarygiftFile2007,anniversarygiftFile2008,anniversarygiftFile2009, anniversarygiftFile2010,anniversarygiftFile2011] """counters"""i=0j=0 """flags used to initialize lists"""
definedFlag=0
definedFlag2=0 for i in range(0,5):
j=0
for row in anniversarygiftFile[i]: if j<=4:
"""skips the first 5 rows"""
elif j==5:
"""initialized the list on the first week of data"""
anniversarygift=[row[1]]
definedFlag = 1
if(i==4):
peakInterestWeeks=[0]
else:
"""appends the list with each row"""
anniversarygift.append(row[1])
if(i==4):
peakInterestWeeks.append(0)
if len(anniversarygift)>=52:
print("i = ",i)
if (i==0):
if(definedFlag==1):
anniversarygiftArray = [anniversarygift]
definedFlag2 = 1
elif (definedFlag == 1):
if(definedFlag2 == 1):
anniversarygiftArray.append(anniversarygift)
break
j=j+1 i=i+1
""" Now all of the data is in python lists""" i=0
j=0
""" Lower peakInterestValue to lower the traffic threshold and discover more peaks """
peakInterestValue=90
""" This is a variable to help you tweak peakInterestValue"""
peakInterestCnt = 0
for i in range(0,5):
print("i =",i)
for j in range (0,51):
if int(anniversarygiftArray[i][j])>peakInterestValue:
"""If keyword interest peaks, peakInterestWeeks[] is incremented"""
peakInterestWeeks[j]=+=1
peakInterestCnt +=1
print("Peak interest",peakInterestWeeks)print("Peak Interest Count =",peakInterestCnt)
"""peakInterestWeeks[] is printed out to a row in an excel file"""
c = csv.writer(open("anniversarygift.csv", "w"))
c.writerow(peakInterestWeeks)
-
Thanks for the feedback. You guys are right about Youmoz. I just submitted it now after adding some screenshots, more thorough directions, etc...keep an eye out for it.
-Zack
-
I totally agree with James here. This looks like it'd be a really helpful post for YouMoz! I would include some screenshots to grab the attention of readers and let them know what kind of results they'll see after they do this and why it's worth their while. Feel free to submit, we'd love to see it!
Keri
-
Hi Mate,
Nice work, I was actually thinking about doing something like this some one was talking about long term insights for search data.
Thank you for putting this togehter but, if you have time you should make a post in the YouMoz blog with this information as it would be better suited to the whole SEO community.
Kind Regards,
James.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
Blog Post Relevance vs Traffic
Hello Moz community, I have a website (lets say that I am selling tshirts), and want to create a blog (www.website.com/blog). With that blog, I would like to post about random topics including travel, leisure, events, new products etc. I want to do this for 1. to get affiliate commissions, 2. to increase web traffic, 3. to potentially increase my domain authority. I would like to know if this blog with random posts would negatively affect my website ranking and keyword ranking (for t-shirts), as it is not relevant to the products that I am selling (and the keywords that I am ranking for). As Google currently understands that my website is a webstore selling t-shirts (and I am ranking for the tshirt keywords), but the algorithm get confused if I start posting about travel and random topics? Your help greatly appreciated in the matter.
SEO Learn Center | | PTurbo1 -
Do I tell MOZ to track both shorter keywords AND the long-winded versions of each shorter keyword?
I understand that my keyword strategy should include a mix of keywords and their long-winded version of the same. And that I should tell Google which keywords each page should rank for. Now when I'm telling MOZ which keywords to monitor for my site's ranking, should I include both the short AND long-winded versions?
SEO Learn Center | | Vitzz
Thanks!0 -
What keywords will this page possibly rank for ... tool?
Hi all, I'm looking for a tool that will look at a web page that you submit to it and tell you what keywords it thinks the page is targetted towards and thus hopefully rank for. Does anyone have any suggestions please? Hopefully this type of tool will help us understand why page A is being ranked for keyword X when page B is actually the page that should be being ranked for that keyword. The only tool I have really found so far is http://www.ranks.nl/tools/spider.html I dont want to tell the tool what keywords I am looking at, as with Moz On page grader. Background reason (and possibly some one maybe able to shed some light on this also). We list a group of products... Nextbase Click 9 Lite, Nextbase Click 9 Lite Duo and Nextbase Click 9 Lite Duo Deluxe. All 3 are similar but very different products and each has its own page on our site. For the keyphrase "Nextbase click 9 lite" currently in Google we are listed for the pages containing the "Nextbase Click 9 Lite Duo" and "Nextbase Click 9 Lite Duo Deluxe"... but not the actual specific product page that targets the "Nextbase Click 9 Lite" product. Thus my reason for wanting to try such a tool that may help me understand why this is. Thanks for any hints, tips or pointers.
SEO Learn Center | | jasef0 -
My Wordpress Organic Blog traffic disappeared and Google is indexing Viagra and Online Med titles for some articles. How to fix that?
Hello, I'm worried that all my organic traffic has disappeared according to Analytics from past friday and now Google is showing results from my title tags in the last days as you can see here: http://goo.gl/QFSgy Is there any additional resources I can read apart from Google Clean Your site Guidelines here https://support.google.com/webmasters/answer/163634 or the Wordpress FAQ for hacked sites here? http://codex.wordpress.org/FAQ_My_site_was_hacked Very much appreciated all of your help! Regards.
SEO Learn Center | | viventuraSEO0 -
Site for my clients to log in and see their traffic, etc.
I have done a ton of research and I am struggling to find an easy to use, easy to understand site / tool that will allow my clients to log in and see basic information about their website traffic, rankings, referring sites, etc. in an ATTRACTIVE, EASY TO UNDERSTAND layout. Any suggestions would be greatly appreciated! Seomoz (my true favorite) Raven, webceo, and so many others are powerful tools - I don't need that, just looking for an attractive place to log in and view their stats, that's it. Thank you - have a great rest of the week! Matthew
SEO Learn Center | | Mrupp440 -
Why did one of our keyword score an F but is first place on Google search? The key word is "Barista Classes Los Angeles"
We're working with an SEO company that provides monthly details on what keywords have improved and needs work. One of our keyowords (Barista Classes Los Angeles) climbed up to number one on Google's search box. However, on SEO Moz, the same keyword got an "F" under the On-Page category. Can someone help us out and define why this is happening? This way, we can adjust and see how we can improve. Thanks!
SEO Learn Center | | ckroaster0 -
Keyword research in 5 different countries. Advice and tips?
Hi guys, We have been asked to research keywords in 5 different countries, Australia, India, South Korea, Brazil, Singapore (4 different languages inc. Portuguese, Korean, English, Indian). Being that I have never conducted keyword research outside of English, I thought maybe you guys could: 1. Point me in the direction of consultants/freelancers who can research terms in those languages. 2. Suggest tips one should bear in mind when designing an SEO strategy for multi-national websites (such as the different SE's used in countries and cultural-behavioral differences) Any articles, guides, tools etc. that can help would be greatly appreciated. Thanks!
SEO Learn Center | | Profero0