This is my code. I tried to concatenate the data but it is showing the empty dataframe. I want the details of symbols provided in the list as output which will be in the form of dataframe.
import pandas as pd
from nsepy import get_history
from datetime import date
symbol=['SBIN','ITC']
data1=[]
data1= pd.DataFrame(data1)
counter=0
for x in symbol:
data = get_history(symbol=x, start=date(2022,4,25), end=date(2022,5,5), index= True)
data = pd.DataFrame(data)
data1= pd.concat([data1,data])
print(x)
print(data1)
The output I am getting is:
SBIN
Empty DataFrame
Columns: [Open, High, Low, Close, Volume, Turnover]
Index: []
ITC
Empty DataFrame
Columns: [Open, High, Low, Close, Volume, Turnover]
Index: []
A couple of things to note here with this solution.
SBINhas x number of fields filled whileNIFTYhas y number of fields filled. So when you concat to create a consolidated dataframe, you get a dataframe with 'NAN' values for the x and y fields ofNIFTYandSBINrespectively. This is a problem with the data and not something you can do much about.data[['Close']].plot()to treat theNANvalues. I have and from what I've observed in the data is that, it does remove, theNANvalues but replaces it with an empty string.NIFTY, INDIAVIX, NIFTY NEXT 50all require theindex=Trueparameter inside theget_history(). However if you setindex=Trueand try to get the data forSBIN, you receive, an empty dataframe. Why they have done so is baffling but you are going to have live with the limitations of their API unless you are able to download this database.With those points out of the way, you can use the following code.
I recommend taking a look at this output in Excel or whatever is comfortable for you when viewing
CSVfiles.