Practical Code Walkthrough | Profit From It
1800 890 4317
profitfromit1@gmail.com

Practical Code Walkthrough

Lesson 8/9 | Study Time: 5 Min

# ✅ Step 1: Install required libraries

!pip install pytrends openpyxl --quiet

!pip install matplotlib pandas --quiet


# ✅ Step 2: Import libraries

import pandas as pd

import matplotlib.pyplot as plt

from pytrends.request import TrendReq


# ✅ Step 3: Initialize Pytrends Connection

pytrends = TrendReq(hl='en-IN', tz=330)


# ✅ Step 4: Set the keywords for the industry

kw_list = ["Electric Vehicle", "EV Charging", "EV India"]  # You can change sector here


# ✅ Step 5: Build payload and fetch data

pytrends.build_payload(kw_list, cat=0, timeframe='today 5-y', geo='IN', gprop='')


# ✅ Step 6: Download Google Trends data

data = pytrends.interest_over_time()


# ✅ Step 7: Clean the data

if 'isPartial' in data.columns:

    data = data.drop(labels=['isPartial'], axis='columns')


# ✅ Step 8: Display the data

print(data.head())


# ✅ Step 9: Plot the trends

plt.figure(figsize=(14,6))

for kw in kw_list:

    plt.plot(data.index, data[kw], label=kw)

plt.title('Google Trends - Sector Demand in India (5 Years)')

plt.xlabel('Year')

plt.ylabel('Search Interest')

plt.grid(True)

plt.legend()

plt.show()


# ✅ Step 10: Save to Excel

data.to_excel('industry_google_trends.xlsx')


print("\n✅ Data exported successfully to Excel!")