Last active
January 18, 2022 12:06
-
-
Save NehaAkashDeo/b22871e188d8e9b4c8d4ce68cd8683b5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pytrends | |
ipywidgets | |
pandas | |
numpy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"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": 7, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Please enter keywords to be searched (Separated by Commas)\n", | |
"\n" | |
] | |
}, | |
{ | |
"data": { | |
"application/vnd.jupyter.widget-view+json": { | |
"model_id": "863e3953345e452bbcc090fa529dc8b8", | |
"version_major": 2, | |
"version_minor": 0 | |
}, | |
"text/plain": [ | |
"interactive(children=(Text(value='India,America', description='kw1'), Output()), _dom_classes=('widget-interac…" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"kw_list=[]\n", | |
"\n", | |
"def display(kw1):\n", | |
" global kw_list\n", | |
" kw_list=kw1.split(\",\")\n", | |
" pytrend.build_payload(kw_list=kw_list, timeframe='today 5-y', geo='IN')\n", | |
" interest_over_time_df=pytrend.interest_over_time()\n", | |
" print(interest_over_time_df)\n", | |
" return kw1\n", | |
"\n", | |
"print(\"Please enter keywords to be searched (Separated by Commas)\\n\")\n", | |
"kw_list=interact(display, kw1=\"India,America\");" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [ | |
{ | |
"ename": "TypeError", | |
"evalue": "'function' object is not iterable", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-4-4c15ecded715>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mpytrend\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbuild_payload\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkw_list\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mkw_list\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtimeframe\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'today 5-y'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mgeo\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'IN'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", | |
"\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pytrends\\request.py\u001b[0m in \u001b[0;36mbuild_payload\u001b[1;34m(self, kw_list, cat, timeframe, geo, gprop)\u001b[0m\n\u001b[0;32m 160\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 161\u001b[0m \u001b[1;31m# build out json for each keyword\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 162\u001b[1;33m \u001b[1;32mfor\u001b[0m \u001b[0mkw\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mkw_list\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 163\u001b[0m keyword_payload = {'keyword': kw, 'time': timeframe,\n\u001b[0;32m 164\u001b[0m 'geo': self.geo}\n", | |
"\u001b[1;31mTypeError\u001b[0m: 'function' object is not iterable" | |
] | |
} | |
], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [ | |
{ | |
"ename": "KeyError", | |
"evalue": "'request'", | |
"output_type": "error", | |
"traceback": [ | |
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", | |
"\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", | |
"\u001b[1;32m<ipython-input-5-d76c75e50dd6>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0minterest_over_time_df\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mpytrend\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minterest_over_time\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0minterest_over_time_df\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;32m~\\anaconda3\\lib\\site-packages\\pytrends\\request.py\u001b[0m in \u001b[0;36minterest_over_time\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 204\u001b[0m over_time_payload = {\n\u001b[0;32m 205\u001b[0m \u001b[1;31m# convert to string as requests will mangle\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 206\u001b[1;33m \u001b[1;34m'req'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mjson\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdumps\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minterest_over_time_widget\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'request'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 207\u001b[0m \u001b[1;34m'token'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0minterest_over_time_widget\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'token'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 208\u001b[0m \u001b[1;34m'tz'\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtz\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", | |
"\u001b[1;31mKeyError\u001b[0m: 'request'" | |
] | |
} | |
], | |
"source": [] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment