Downloading NSE stock data from internet

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web

#define date from and to
start = dt.datetime(2015,4,1)
end = dt.datetime(2021,5,4)

#function for importing data from yahoo finance and saving to csv
def getdata(ticker):
dataread = web.DataReader(ticker,’yahoo’,start,end)
dataread.to_csv(“E:/nse/”+ticker+”.csv”)

df = pd.read_csv(“E:/nse/nifty500.csv”)

# for nse data yahoo has .NS in ticker name end

df[‘Symbol’] = df[‘Symbol’]+ ‘.NS’

# create csv
df[‘Symbol’].apply(getdata)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store