DigitalOcean Referral Badge
Udit Vashisht
Author: Udit Vashisht


Download Latest NIFTY 50 Stocks List 2022 using Two Lines of Python Code

  • 3 minutes read
  • 7 Views
Download Latest NIFTY 50 Stocks List 2022 using Two Lines of Python Code

    Table of Contents

How to download latest NIFTY 50 Stocks List 2022 using just two lines of Python Code?

In this tutorial, we will use python to download the latest NIFTY 50 stocks. We will be using the official NSE website to source the link to the CSV File. Hence, this method will be useful to download the latest Nifty 50 stocks no matter when are you using this tutorial.

Python code to download NIFTY 50 Stocks List 2022

We will be using Python and Jupyter Notebook for downloading the NIFTY 50 stocks list. We will be using following modules to download and saving the list of Nifty 50 stocks:

  1. Python
  2. Jupyter Notebook
  3. Pandas
  4. Pickle

Further, we will be using the download csv link from NSE’s official website to download the CSV file and read it as a pandas dataframe.

So open a terminal and run the following command.

jupyter notebook

This will open the jupyter notebook in your default browser. In the Jupyter notebook create a new python file. and add the following code:-

import pandas as pd
import pickle
URL = 'https://www1.nseindia.com/content/indices/ind_nifty50list.csv'
df = pd.read_csv(URL, index_col = 'Company Name')
df

Here, we have read the csv file directly into Pandas and created a Pandas Dataframe, further, we have set ‘Company Name’ as Index. To learn more about setting an index of the Pandas dataframe, you can read this post. Running the code will give you following result:-

SCR-20220622-h5l.png

Here, you can see that, we have got the list of all the NIFTY 50 stocks from csv and it has Company Name, Industry, Symbol, Series and ISIN code of NIFTY 50 stocks.

How to extract a list of NIFTY 50 stock symbols from the CSV.

Further, in most of the cases, you will be needing just the symbol of the stocks, so we will be extracting the symbols and creating a Python List.

nifty_50_list = df['Symbol'].tolist()
nifty_50_list

This, will give us a list of NIFTY 50 stocks symbols which can be used anytime.

Creating a pickle file of NIFTY 50 stocks for future use

Thereafter, we will creating a pickle of the list, so that it can be used in any of the projects in future. To do that, we have to use the following code:-

with open('NIFTY50.pickle', 'wb') as f:
    pickle.dump(nifty_50_list, f)

This will create a pickle file which can be use in any of your project and to extract the list, you will simply have to use the following code:-

with open('NIFTY50.pickle', 'rb') as f:
    nifty_50 = pickle.load(f)

Download Latest NIFTY 50 Stocks List 2022 using Two Lines of Python Code - Video Tutorial


Related Posts

Get an automated email on availability of Covishield and Covaxin on Cowin
By Udit Vashisht

How to get an automated email on availability of Covishield and Covaxin on Cowin website?

I have created a Python Script which can be used to send automated email if the COVID-19 Vaccine (Covishield or Covaxin) is available on the Indian Government’s Cowin Portal for any age group ...

Read More
How to use Python to download Historical Data of NSE Stocks?
By Udit Vashisht

Stop manually downloading the historical data of NSE stocks, use Python instead

If you are manually downloading the historical or daily data for the stocks from NSE, you should stop doing that and start using Python to do the same. There are many benefits of using Python to download historical ...

Read More
New Walrus Operator in Python 3.8
By Udit Vashisht

What is new walrus operator in Python 3.8?

The official version of Python 3.8 was released in October, 2019.

What’s new in Python 3.8?

Before going in details about new Walrus Operator in Python 3.8, I will like to summarize what is new in Python 3.8 :-

Read More
Search
Tags
tech tutorials automate python beautifulsoup web scrapping webscrapping bs4 Strip Python3 programming Pythonanywhere free Online Hosting hindi til github today i learned Windows Installations Installation Learn Python in Hindi Python Tutorials Beginners macos installation guide linux SaralGyaan Saral Gyaan json in python JSON to CSV Convert json to csv python in hindi convert json csv in python remove background python mini projects background removal remove.bg tweepy Django Django tutorials Django for beginners Django Free tutorials Proxy Models User Models AbstractUser UserModel convert json to csv python json to csv python Variables Python cheats Quick tips == and is f string in python f-strings pep-498 formatting in python python f string smtplib python send email with attachment python send email automated emails python python send email gmail automated email sending passwords secrets environment variables if name == main Matplotlib tutorial Matplotlib lists pandas Scatter Plot Time Series Data Live plots Matplotlib Subplots Matplotlib Candlesticks plots Tutorial Logging unittest testing python test Object Oriented Programming Python OOP Database Database Migration Python 3.8 Walrus Operator Data Analysis Pandas Dataframe Pandas Series Dataframe index pandas index python pandas tutorial python pandas python pandas dataframe python f-strings padding how to flatten a nested json nested json to csv json to csv python pandas Pandas Tutorial insert rows pandas pandas append list line charts line plots in python Django proxy user model django custom user model django user model matplotlib marker size pytplot legends scatter plot python pandas python virtual environment virtualenv venv python python venv virtual environment in python python decorators bioinformatics fastafiles Fasta python list append append raspberry pi editor cron crontab Cowin Cowin api python dictionary Python basics dictionary python list list ios development listview navigationview swiftui ios mvvm swift environmentobject property wrapper @State @Environm popup @State ios15 alert automation instagram instaloader texteditor youtubeshorts textfield multi-line star rating reusable swift selenium selenium driver requests-html youtube youtube shorts python automation python tutorial algo trading nifty 50 nifty50 stock list nifty50