gpt4 book ai didi

excel - 如何以 Excel 日期为键对 Deedle 框架进行索引?

转载 作者:行者123 更新时间:2023-12-02 17:42:33 25 4
gpt4 key购买 nike

假设我有一个“日期”列,其值如下所示: 86年3月10日、86年6月10日、86年7月10日等...

这并不像Frame.indexRowsDate("Date")那么简单。我当前的解决方案是在 Excel 3 上创建额外的列:

  • 年份
  • 月份

具有值:

  • =年份(A2)
  • =月份(A2)
  • =日(A2)

(对于第 2 行,其中 A 是包含日期的列)

然后使用这个函数:

let toDateTime (os:ObjectSeries<_>) =
let year = (os.Get "Year") :?> int)
let month = (os.Get "Month" :?> int)
let day = (os.Get "Day" :?> int)
DateTime(year,month,day)

Frame.indexRowsUsing toDateTime frame

解决方案根据提供的答案,新的 toDateTime 如下所示:

let toDateTime (os:ObjectSeries<_>) =
DateTime.Parse((os.Get "Date") :?> string)

最佳答案

您不能使用 DateTime 的构造函数并向其提供字符串。

let d = new DateTime("03/10/86")

但是你可以使用静态成员TryParse它将返回一个元组给你

let (success, date) = DateTime.TryParse("03/10/86")
if success then
//use date here
else
//do some error handling

关于excel - 如何以 Excel 日期为键对 Deedle 框架进行索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41880637/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com