i am trying to use historical data output as record. this output is in for of array. to access previous candle data i am using pandas(suggest if anything is better).
See if you can use the below function which I had written for my use: def capture_fn(his,inst): his=kite_Accnt1.historical(int(nse_inst['Instrument_Type'][Inst]),day1,day2,'minute') Close=[k['close'] for k in his] Open_1=[k['open'] for k in his] Low=[k['low'] for k in his] High=[k['high'] for k in his] date1=[k['date'] for k in his] Volume=[k['volume'] for k in his] df=pd.DataFrame([Close,Open_1,Low,High,date1,Volume]).transpose() df.columns=['Close','Open','Low','High','Date','Volume'] df['Inst']=[inst for k in Close] #df['date_1']=[day for k in Close] return df Regards, Naveen
@menaveenn Hi, Close=[k['close'] for k in his] Open_1=[k['open'] for k in his] Low=[k['low'] for k in his] High=[k['high'] for k in his] date1=[k['date'] for k in his] Volume=[k['volume'] for k in his] df=pd.DataFrame([Close,Open_1,Low,High,date1,Volume]).transpose() df.columns=['Close','Open','Low','High','Date','Volume']
@AnkitDoshi Basically if you have more data points like open,close,low ,high and other details like volume etc ,in that case we can take whatever data points required and you can store only those in lists and later we can create a dataframe with them.
I used read huge content from elasticsearch(in my office ) in that case some times my server goes out of memory due to unnecessary datapoints ,so we used run in batches and store only required columns/datapoints which are required.
Here its not required ,but I'm still using it as a practice.
This error message suggests that a function or operation is expecting an index to be passed, but one was not provided. This can occur when attempting to access or manipulate elements of an array without specifying the index of the element to be accessed or manipulated. To resolve this error, ensure that the appropriate index or indices are specified when attempting to access or manipulate array elements. If working with scalar values, pass an index to indicate which value should be used.
See if you can use the below function which I had written for my use:
def capture_fn(his,inst):
his=kite_Accnt1.historical(int(nse_inst['Instrument_Type'][Inst]),day1,day2,'minute')
Close=[k['close'] for k in his]
Open_1=[k['open'] for k in his]
Low=[k['low'] for k in his]
High=[k['high'] for k in his]
date1=[k['date'] for k in his]
Volume=[k['volume'] for k in his]
df=pd.DataFrame([Close,Open_1,Low,High,date1,Volume]).transpose()
df.columns=['Close','Open','Low','High','Date','Volume']
df['Inst']=[inst for k in Close]
#df['date_1']=[day for k in Close]
return df
Regards,
Naveen
You can do this directly
Data= kite.historical(instrument_token , from_dt , to_dt , interval)
Data=pd.DataFrame(Data)
For rearranging and setting index
Data=Data[['date','open','high','low','close','volume']]
Data=Data.set_index('date')
Hi,
Close=[k['close'] for k in his]
Open_1=[k['open'] for k in his]
Low=[k['low'] for k in his]
High=[k['high'] for k in his]
date1=[k['date'] for k in his]
Volume=[k['volume'] for k in his]
df=pd.DataFrame([Close,Open_1,Low,High,date1,Volume]).transpose()
df.columns=['Close','Open','Low','High','Date','Volume']
what will this code do?
Is it renaming column?
I used read huge content from elasticsearch(in my office ) in that case some times my server goes out of memory due to unnecessary datapoints ,so we used run in batches and store only required columns/datapoints which are required.
Here its not required ,but I'm still using it as a practice.
Regards,
Naveen