Skip to content

Instantly share code, notes, and snippets.

@NehaAkashDeo
Last active July 27, 2020 11:16
Show Gist options
  • Select an option

  • Save NehaAkashDeo/e9e8afe01b4be6abe6c1073a8d09095b to your computer and use it in GitHub Desktop.

Select an option

Save NehaAkashDeo/e9e8afe01b4be6abe6c1073a8d09095b to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nbi:hide_in \n",
"\n",
"import pytrends\n",
"from ipywidgets import interact\n",
"from pytrends.request import TrendReq\n",
"pytrend = TrendReq()\n",
"import pandas as pd "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# nbi:hide_in\n",
"\n",
"kw_list=[]\n",
"\n",
"def display(kw1):\n",
" global kw_list\n",
" kw_list=kw1.split(\",\")\n",
" print(kw_list)\n",
" return kw1\n",
"\n",
"kw_list=interact(display, kw1=\"Modi,Trump\");\n",
"print(kw_list)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nbi:hide_in \n",
"\n",
"pytrend.build_payload(kw_list=kw_list, timeframe='today 5-y', geo='IN')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nbi:hide_in \n",
"\n",
"interest_over_time_df=pytrend.interest_over_time()\n",
"print(interest_over_time_df)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nbi:hide_in \n",
"\n",
"from matplotlib import pyplot as plt \n",
"import time\n",
"import datetime\n",
"from datetime import datetime, date, time\n",
"\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# nbi:hide_in \n",
"\n",
"dx= interest_over_time_df.plot.line(figsize=(12,8), title=\"Interest over time\",colormap=\"Set1\", linewidth=3)\n",
"dx.set_xlabel(\"Date\", fontsize=22)\n",
"dx.set_ylabel(\"Interest Over Time\", fontsize=22)\n",
"dx.tick_params(axis='both', which='major', labelsize=22)\n",
"dx.set_title('Comparison Across Keywords',fontsize=30)\n",
"dx.legend(fontsize=15)\n",
"\n",
"dx.text(2640,-2,'Machine Generated Insights', style='italic', bbox={'facecolor': 'grey', 'alpha': 0.5, 'pad': 3}, rotation=270)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
ipywidgets
pytrends
pandas
matplotlib
ipython
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment