【发布时间】:2018-09-03 01:21:40
【问题描述】:
我想要一个 ohlc 表来稍后分析蜡烛模式,使用当前代码如下所示,我可以看到我的 ohlc 表,但“蜡烛”与数据系列不匹配。
# my testing code
import pandas as pd
df = pd.read_csv('tmp/NEG_20180829.txt', header=None, delimiter="\;", skiprows=1,
names=["Session Date", "Symbol", "Deal Number", "Deal Price",
"Quantity", "Hour", "Ind Cancel", "Offer Date", "Seq Offer Date",
"GenerationID", "Deal Condition", "Date Sell Offer", "Sequence Sell Offer",
"Generation Id Sell", "Sell Condition", "Indicator", "Broker Buy", "Broker Sell"],
)
df.index = pd.to_datetime(df.index, unit='m')
ticks = df.loc[df.index, ['Deal Price', 'Quantity']]
bars = ticks['Deal Price'].resample('1min', how='ohlc')
print(bars)
和我的输出:
open high low close
1970-01-01 00:00:00 18.50 18.50 18.50 18.50
1970-01-01 00:01:00 18.50 18.50 18.50 18.50
1970-01-01 00:02:00 18.50 18.50 18.50 18.50
1970-01-01 00:03:00 18.50 18.50 18.50 18.50
1970-01-01 00:04:00 18.50 18.50 18.50 18.50
1970-01-01 00:05:00 18.50 18.50 18.50 18.50
1970-01-01 00:06:00 18.50 18.50 18.50 18.50
1970-01-01 00:07:00 18.50 18.50 18.50 18.50
1970-01-01 00:08:00 18.50 18.50 18.50 18.50
看起来熊猫无法识别数据系列,因为正如我们在文件示例中看到的那样,日期和时间位于不同的字段中,我该如何合并它们?
文件示例:
2018-08-29;APPL ;0000000290; 000000000018.500000;000000000000002200;10:08:11.899;1;2018-08-29;000082181828559;000000004182711;2;2018-08-29;000082181827277;000000004182712;2;0;00000308;00000021
2018-08-29;APPL ;0000000300; 000000000018.500000;000000000000000100;10:08:11.899;1;2018-08-29;000082181828266;000000004182713;2;2018-08-29;000082181827277;000000004182714;2;0;00000308;00000021
2018-08-29;APPL ;0000000390; 000000000018.500000;000000000000001000;10:08:11.899;1;2018-08-29;000082181826807;000000004182731;2;2018-08-29;000082181828365;000000004182732;2;0;00000003;00000386
2018-08-29;AAPL ;0000000440; 000000000018.500000;000000000000000500;10:08:11.899;1;2018-08-29;000082181825761;000000004182741;2;2018-08-29;000082181827689;000000004182742;2;0;00000003;00000003
【问题讨论】: