[英]How to resample tick data to pandas resample ohlc
I am trying to convert fx tick data into ohlc data: 我正在尝试将fx刻度数据转换为ohlc数据:
import pandas as pd
data_frame = pd.read_csv('gbpusd jan17.csv', names=['Symbol', 'Date_Time', 'Bid', 'Ask'],
index_col=1, parse_dates=True, nrows=100)
print(data_frame.head())
data_ask = data_frame['Ask'].resample('15Min').ohlc()
data_bid = data_frame['Bid'].resample('15Min').ohlc()
data_ask.head()
data_bid.head()
print(data_ask.head())
print(data_ask[1:5])
My outputs are: 我的输出是:
Symbol Bid Ask
Date_Time
2017-01-02 00:00:01.105 GBP/USD 1.23399 1.23551
2017-01-02 00:00:01.561 GBP/USD 1.23399 1.23551
2017-01-02 00:00:05.122 GBP/USD 1.23399 1.23551
2017-01-02 00:00:05.525 GBP/USD 1.23365 1.23577
2017-01-02 00:00:06.139 GBP/USD 1.23365 1.23577
open high low close
Date_Time
2017-01-02 1.23551 1.23633 1.23551 1.23576
Empty DataFrame
Columns: [open, high, low, close]
Index: []
Can anyone please tell me why I can see head of an empty dataframe? 谁能告诉我为什么我可以看到一个空数据框的头部? What went wrong here and how can I turn all tick data to ohlc data?
这里出了什么问题,我该如何将所有报价数据转换为ohlc数据?
It appears that data_ask
is a single row dataset (based on the previous head()
statement). 看来
data_ask
是单行数据集(基于先前的head()
语句)。 But when you use [1:5]
to call the data, you're asking for the set of data starting at the second row, thus the empty df. 但是,当您使用
[1:5]
调用数据时,您会要求从第二行开始的数据集,即空df。 See what happens if you use print(df_ask[0:5])
instead. 看看如果使用
print(df_ask[0:5])
会发生什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.