Skip to content

Instantly share code, notes, and snippets.

@codewithpom
Created November 17, 2021 15:06
Show Gist options
  • Save codewithpom/92c9de6affd1306cc5c0622e52da60a8 to your computer and use it in GitHub Desktop.
Save codewithpom/92c9de6affd1306cc5c0622e52da60a8 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells":[
{
"cell_type":"code",
"source":[
"from pytrends.request import TrendReq # For Trend analysis\n",
"import plotly.express as px # For ploting it\n",
"\n",
"pytrends = TrendReq(hl='en-US', tz=360) # Initialize the trend object"
],
"execution_count":2,
"outputs":[
],
"metadata":{
}
},
{
"cell_type":"code",
"source":[
"# build payload\n",
"\n",
"kw_list = [\"Python\", 'Java'] # list of keywords to get data \n",
"\n",
"pytrends.build_payload(kw_list, cat=0, timeframe='today 12-m') # create payload"
],
"execution_count":13,
"outputs":[
],
"metadata":{
}
},
{
"cell_type":"code",
"source":[
"#1 Interest over Time\n",
"data = pytrends.interest_over_time() \n",
"data = data.reset_index()\n",
"\n",
"\n",
"fig = px.line(data, x=\"date\", y=kw_list, title='Keyword Web Search Interest Over Time')\n",
"fig.show() "
],
"execution_count":14,
"outputs":[
{
"data":{
"text\/plain":[
"Unsupported"
]
},
"metadata":{
},
"output_type":"display_data"
}
],
"metadata":{
}
}
],
"metadata":{
},
"nbformat":4,
"nbformat_minor":0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment