open high low close Volume
ctime
2022-11-07 01:00:00.012000+01:00 20900.0 20900.0 20900.0 20900.0 209.00
2022-11-07 01:00:00.019000+01:00 20900.1 20900.1 20900.1 20900.1 1254.00
2022-11-07 01:00:00.111000+01:00 20900.0 20900.0 20900.0 20900.0 11390.50
2022-11-07 01:00:00.188000+01:00 20900.1 20900.1 20900.1 20900.1 20.90
2022-11-07 01:00:00.194000+01:00 20900.0 20900.0 20900.0 20900.0 4995.10
2022-11-07 01:00:00.203000+01:00 20900.0 20900.0 20900.0 20900.0 209.00
2022-11-07 01:00:00.217000+01:00 20900.0 20900.0 20900.0 20900.0 239827.50
2022-11-07 01:00:00.237000+01:00 20900.0 20900.0 20900.0 20900.0 20.90
2022-11-07 01:00:03.028000+01:00 20900.0 20900.0 20900.0 20900.0 20.90
2022-11-07 01:00:03.743000+01:00 20900.0 20900.0 20900.0 20900.0 41.80我需要集中在五个交易的时期,也就是说,开盘是第一行,收盘是第五笔交易,最低和最高是对应的最小和最高的5笔交易,同样是成交量。一旦转换完成,公开的示例中应该只剩下2行。
我试过寻找熊猫的近似值,但我没有找到令人满意的解决方案。
发布于 2022-11-11 22:50:12
定义一个新的系列,将交易分成5组,然后按组汇总:
trade_group = np.arange(len(df)) // 5
# The `open` of the group is the `open` of the first trade in the group
# `high` is max of the `high` in the group
# and so on...
df.groupby(trade_group).agg({
"open": "first",
"high": "max",
"low": "min",
"close": "last",
"Volume": "sum"
})https://stackoverflow.com/questions/74408676
复制相似问题