Pylenin Weekly #12
if name equals main and an unofficial introduction to Pytrends - Google Trends API for Python.
Welcome to Pylenin Weekly #12, a newsletter dedicated to improving the lives of my fellow peers through knowledge sharing in the field of programming and Data.
I would like to apologize for delaying the newsletter by 2 days! I have been traveling for work and because of that, I was unable to write the newsletter with the utmost quality that I want to maintain.
Last week, I showed you the best way to set up your database settings for Django and Flask. I also make a Twitter version for it, which seems to be getting a lot of retweets! So I would like to share it with you here.
This week, we are going to get into one of the topics in Python that is very basic but still confusing to a lot of beginners!
What does if __name__ == "__main__" do in Python?
Check out this article on this topic that I wrote recently.
An "unofficial" introduction to Pytrends
Before you begin, let me be totally frank with you! This is an unofficial package for the Google Trends API.
So if it stops working for you, know that Google has changed its backend!
We will try to figure out the popularity of Python over the last few years on Google Trends.
Step 1 - Connect to google
from pytrends.request import TrendReq import matplotlib.pyplot as plt pytrends = TrendReq(hl='en-US', tz=360)
Step 2 - Build a payload
kw_list = ["Python"] pytrends.build_payload(kw_list, timeframe='today 5-y')
Step 3 - Check the interest in your keyword over time
pytrends.interest_over_time() df['Python'].plot(figsize = (20,10), color = 'blue') plt.show()
As obvious, the popularity of Python is here to grow!! So our jobs are secure :-D
You can add your own modifications to this code. For example - We have found interest over time for the "Python" keyword. You can also find interest over a region.
Check out the documentation and make sure to tweet to me with some new information.
Here are some things you could try!
- Find out interest for "Python" in India.
- Find out how "machine learning" has trended compared to "Python" in the last 5 years.
Hope you enjoyed today's newsletter! Next week, I will be back again with something new and interesting. Till then, take care!