Advertisement
bolverk

trends_playground

Apr 17th, 2022
1,117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import numpy as np
  2. import pandas as pd
  3. from pytrends.request import TrendReq
  4. import pylab
  5. from hijri_converter import Hijri, Gregorian
  6.  
  7. query = 'רקטות'
  8. pytrend = TrendReq()
  9. kw_list = [query]
  10. pytrend.build_payload(kw_list,
  11.                       timeframe='all')
  12. iot = pytrend.interest_over_time()
  13. search_months = pd.DatetimeIndex(iot.index).month
  14. search_years = pd.DatetimeIndex(iot.index).year
  15. tally = np.zeros(12)
  16. htally = np.zeros(12)
  17. for year, month, searches in zip(
  18.         search_years,
  19.         search_months,
  20.         iot[query].values):
  21.     tally[month-1] += searches
  22.     h = Gregorian(year, month, 15).to_hijri()
  23.     htally[h.month-1] += searches
  24.    
  25. # Plotting
  26. pylab.subplot(211)
  27. pylab.bar(list(range(1, 13)),
  28.           tally)
  29. pylab.title('Google trends for '+query[::-1]+' since 2004')
  30. pylab.xlabel('Gregorian month')
  31.  
  32. pylab.subplot(212)
  33. pylab.bar(list(range(1, 13)),
  34.           htally)
  35. pylab.xlabel('Islamic month')
  36.  
  37. pylab.tight_layout()
  38. pylab.show()
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement