我正在尝试将1M OHLC转换为5M OHLC,以便使用pandas创建一系列文件
我的数据是这样的:
dateTime | open | high | low | close | vol |
-----------------------------------------------------------
01-06-2018 00:50:00 | 0.97456| 0.2456|0.2145|0.241|54.26
01-06-2018 00:51:00 | 0.94566| 0.2145|0.1455|0.214|65.24
01-06-2018 00:52:00 | 0.89654| 0.2145|0.2144|0.214|73.25如何重采样并另存为5M OHLC csv
提前感谢
编辑1:这是我使用print (df.info())得到的结果
<class 'pandas.core.frame.DataFrame'>
Index: 375660 entries, 2018-06-01 00:00:00 to 2019-05-31 20:59:00
Data columns (total 4 columns):
open 375660 non-null float64
high 375660 non-null float64
low 375660 non-null float64
close 375660 non-null float64
dtypes: float64(4)
memory usage: 14.3+ MB
None发布于 2019-08-08 20:22:54
对列名使用Resampler.agg with dictionary结合使用5T for 5 minutes进行聚合
d = {'open':'first', 'high':'max','low':'min','close':'last','vol':'sum'}
df['dateTime'] = pd.to_datetime(df['dateTime'])
df = df.resample('5T', on='dateTime').agg(d)
print (df)
open high low close vol
dateTime
2018-01-06 00:50:00 0.97456 0.2456 0.1455 0.214 192.75https://stackoverflow.com/questions/57412414
复制相似问题