Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.

Python to pull data for Nifty 50 stocks and save it as an Excel file

Last updated on 17 hours ago
C
caaSuper Admin
Posted 17 hours ago
To get all Nifty 50 stocks into an Excel sheet, you can use the NSE India website, an API, or a web scraping method. Here are three methods:
Method 1: Manual Download from NSE India

Go to the NSE India website: https://www.nseindia.com/market-data/live-equity-market.
Click on Nifty 50 under the benchmark indices section.
Select the option to Download CSV (usually available on the page).
Open the downloaded file in Excel.
C
caaSuper Admin
Posted 18 hours ago
you can use Python to pull data for Nifty 50 stocks and save it directly as an Excel file:
Steps:
Install yfinance and pandas if you haven't already:
pip install yfinance pandas openpyxl

Run the following code to fetch the Nifty 50 stocks and save them in an Excel file:
 import yfinance as yf
 import pandas as pd

 # Fetch Nifty 50 tickers (replace with actual tickers if needed)
 nifty50_tickers = [
 "RELIANCE.NS", "TCS.NS", "HDFCBANK.NS", "INFY.NS", "HINDUNILVR.NS",
 "ICICIBANK.NS", "HDFC.NS", "SBIN.NS", "KOTAKBANK.NS", "BHARTIARTL.NS",
 # Add all other tickers here
 ]

 # Fetch data and create a DataFrame
 data = {ticker: yf.Ticker(ticker).info for ticker in nifty50_tickers}
 df = pd.DataFrame(data).T # Transpose for a better view
# Select and clean the columns as needed
 df = df[['symbol', 'longName', 'sector', 'marketCap']]
 # Save to Excel
 df.to_excel("Nifty50_Stocks.xlsx", index=False)
 print("Data saved to Nifty50_Stocks.xlsx")


This code fetches basic data on Nifty 50 stocks like name, sector, and market cap, but you can add more fields as required. The final output is an Excel file named Nifty50_Stocks.xlsx in the current directory.
Edited by caa on 25-10-2024 06:48, 18 hours ago
You can view all discussion threads in this forum.
You cannot start a new discussion thread in this forum.
You cannot reply in this discussion thread.
You cannot start on a poll in this forum.
You cannot upload attachments in this forum.
You cannot download attachments in this forum.
Sign In
Not a member yet? Click here to register.
Forgot Password?
Users Online Now
Guests Online 1
Members Online 0

Total Members: 11
Newest Member: Jhilam