How do I get date column from nsepy get-history function

865 Views Asked by At

I am not able to get this date column which is visible in the below given image.enter image description here

I want to store this date in another dataframe

I have tried this:

sbin['Date']

but its not working

complete code:

from datetime import date
import datetime
from nsepy import get_history
import pandas as pd

enddate = datetime.datetime.today()
startdate = enddate - datetime.timedelta(10)
sbin = get_history(symbol='SBIN',
                   start=startdate,
                   end=enddate)
print(type(sbin))
sbin
2

There are 2 best solutions below

0
Kiran Hosur On BEST ANSWER

#You are trying to access pandas.core.internals.BlockManager. So in order to get date you need to get the block manager first and then get the axis :

Bm = sbin._data
date_time = Bm.axes[1] 
print(date_time)
#if you want to access individual element access like a list
date_time[0]

Hope this helps you.

0
GS Singh On

Try this:

from nsepy import get_history
from datetime import date
data = get_history(symbol="SBIN", start=date(2015,1,1), end=date(2015,1,31))
data[['Close']].plot()

ref: https://nsepy.xyz/