Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences…

Follow publication

How to get Indian stock data using pandas_datareader?

--

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.

Sign up to discover human stories that deepen your understanding of the world.

--

--

Nerd For Tech
Nerd For Tech

Published in Nerd For Tech

NFT is an Educational Media House. Our mission is to bring the invaluable knowledge and experiences of experts from all over the world to the novice. To know more about us, visit https://www.nerdfortech.org/.

Tushar Tiwari
Tushar Tiwari

Written by Tushar Tiwari

Finding insights from data | Fascinated by how Markets works.

No responses yet

Write a response