How to get Indian stock data using pandas_datareader?

Tushar Tiwari
Nerd For Tech
Published in
1 min readJul 17, 2021

--

In this blog post, I will guide you through how to get stock data of #NSE (National Stock Exchange data).

Data collection is often the most overlooked part by the beginner Data Scientist.

Let’s get Started

  1. Get a list of stock tickers. Link for Most liquid and F & O stock.

2. Install pandas_datareader: using

pip install pandas_datareader

3. Some required imports:

import pandas as pd
import pandas_datareader as pdr
import time

4. Extracting the stock symbol names.

Stock Selection

5. Defining a function named fetch_data which takes input as the symbol name and saves the stock prices in the specified directory here it is ‘stock_data/’.

Extracting stock data function

6. Running the fetch_data function for the selected stocks.

Fetching stock data for selected stocks

Here I have used time.sleep(10) as Yahoo API is stopping form making many requests in short time.

Note: This does not work in google colab so try this on your computer.

--

--

Tushar Tiwari
Nerd For Tech

Finding insights from data | Fascinated by how Markets works.