我使用创建了一个数据框
// Create a dataframe containing the Open, High, Low, and Close
let ohlc =
cl
|> Frame.sliceCols ["Open"; "High"; "Low"; "Close"; "Volume"]
结果输出: Open High Low Close Volume 12/28/2014 8:00:00 PM -> 62.13 62.67 62.13 62.27 3206
12/28/2014 9:00:00 PM -> 62.27 62.42 62.14 62.39 1620
12/28/ 2014 10:00:00 PM -> 62.4 62.41 62.16 62.21 1275
12/28/2014 11:00:00 PM -> 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:022:00 -> 6。 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 不需要。