尝试将 1 分钟的 ohlc 转换为 1 天的股票数据。
我有两个数据框
df - 1 分钟数据帧
我正在尝试制作的 df2- 1 天数据框
df 有以下列
cols = ["name", "date","time", "open", "high","low","close","sm","volume"]
我正在像这样初始化 df2
df2 = pd.DataFrame( columns = ["name", "date", "open", "high","low","close"])
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
就像这个 df 有整个月的 1 分钟数据。
我想从 df 插入 1 天到 df2。
对于初学者,我尝试像这样首先将当天的开盘价和收盘价插入 df2
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]
这让我返回错误
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
我应该怎么办?
另外,考虑到 df 有整个月的 1 分钟数据,我怎样才能获得每天的最低价和最高价?
郎朗坤
相关分类