Trying to convert 1 min ohlc into 1 day stock data.
I have two dataframes
- df - 1min dataframe
- df2- 1 day dataframe which I'm trying to make
df has the following columns
cols = ["name", "date","time", "open", "high","low","close","sm","volume"]
I'm initialising df2 like this
df2 = pd.DataFrame( columns = ["name", "date", "open", "high","low","close"])
Sample data of df
name date time open high low close sm volume
BANKNIFTY_F1 20190101 09:16 27300.2 27368.1 27300.2 27314.9 18300 1414860
BANKNIFTY_F1 20190101 09:17 27317.7 27322.1 27289.9 27299.3 11980 1414860
BANKNIFTY_F1 20190101 09:18 27298.6 27309.0 27296.2 27307.0 10760 1414860
BANKNIFTY_F1 20190101 09:19 27302.7 27308.7 27277.0 27282.0 13620 1424420
BANKNIFTY_F1 20190101 09:20 27282.0 27282.0 27257.5 27264.4 16040 1424420
Like this df has 1 min data for an entire month.
And I want to insert 1 day from df into df2.
For starters I tried to insert the open and close price of the day first into df2 like this
for j in range(df['date'].nunique()):
#open and close
for i in range(len(df)):
#open
if(df['time'][i]=='09:16'):
df2['open'][j]=df['open'][0]
#close
if(df['time'][i]=='15:30'):
df2['close'][j]=df['close'][i]
This is returning me with error
File "<ipython-input-26-43c7b22fee98>", line 1, in <module>
df2['open'][0]=df['open'][0]
File "/home/devang/anaconda3/lib/python3.7/site-packages/pandas/core/series.py", line 1020, in __setitem__
values[key] = value
IndexError: index 0 is out of bounds for axis 0 with size 0
What should I do?
Also how can I can get the lowest and highest price of each day considering df has 1min data for an entire month in it?