如何使用Excel的日期作为键索引Deedle Frame?

时间:2017-01-26 18:41:14

标签: excel dataframe f# deedle

说我给了一个专栏" Date"值看起来像:     03/10 /86,06 / 10 / 86,77 / 10/86等...

这不像做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)

1 个答案:

答案 0 :(得分:3)

您无法使用DateTime的构造函数并为其提供字符串。

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

但您可以使用static member TryParse来返回一个元组

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