【发布时间】:2016-04-07 00:02:01
【问题描述】:
我已经使用
创建了一个数据框// Create a dataframe containing the Open, High, Low, and Close
let ohlc =
cl
|> Frame.sliceCols ["Open"; "High"; "Low"; "Close"; "Volume"]
结果输出:
开高低收盘量
2014 年 12 月 28 日晚上 8:00:00 -> 62.13 62.67 62.13 62.27 3206
2014 年 12 月 28 日晚上 9:00:00 -> 62.27 62.42 62.14 62.39 1620
2014 年 12 月 28 日晚上 10:00:00 -> 62.4 62.41 62.16 62.21 1275
2014 年 12 月 28 日晚上 11:00:00 -> 62.21 62.32 61.96 62.19 2791
12/29/2014 12:00:00 AM -> 62.17 62.25 62.08 62.23 1233
2014 年 12 月 29 日凌晨 1:00:00 -> 62.23 62.41 62.21 62.31 1186
2014 年 12 月 29 日凌晨 2:00:00 -> 62.32 62.32 62.07 62.21 1446
2014 年 12 月 29 日凌晨 3:00:00 -> 62.22 62.35 62.17 62.28 1335
我现在想从上述每小时样本中生成更高的时间范围(每天)。
我开始:
ohlc
|> Frame.rows
|> Series.resampleEquiv (fun d -> d.Date)
返回:
Series<DateTime,Series<DateTime,ObjectSeries<string>>>.
我想创建一个新的 DataFrame,其中包含 Date(key)、Open、High、Low、Close 和 Volume 列。打开是该系列第 1 行中的第一个打开。 High 是该系列中的 Max High。低是该系列中的最低低。 Close 是该系列中的最后一个 Close。 Volume是系列中Volume的总和
比如:
ohlc
|> Frame.rows
|> Series.resampleEquiv (fun d -> d.Date)
|> ??
|> ??
与其尝试使用 Rows 在 Frame 级别执行此操作,不如尝试使用 Columns 使用 Frame 执行此操作?
更新 这是完成的代码:
ohlc
|> Frame.rows
|> Series.resampleEquiv (fun d -> d.Date)
|> Series.mapValues (fun s ->
let temp = Frame.ofRows s
series ["Open" => Series.firstValue temp?Open
"High" => defaultArg (Stats.max temp?High) nan
"Low" => defaultArg (Stats.min temp?Low) nan
"Close" => Series.lastValue temp?Close
"Volume" => defaultArg (Some( Stats.sum temp?Volume) ) nan ] )
|> Frame.ofRows
我无法使用:
"Volume" => defaultArg (Stats.sum temp?Volume) nan ] )
因为这给了我一个错误消息:这个表达式应该有类型浮点选项,但这里有浮点类型。我不得不包装函数 Some()。不知道为什么 Stats.sum 需要这个,但 Stat.max 和 Stats.min 不需要。
【问题讨论】: