如何使用Excel的date作为键索引一个Deedle框架?
假设我给了一个“date”列,其值为03/10/86,06/10/86,07/10/86等。
这并不像Frame.indexRowsDate("Date")
那么简单。 我目前的解决scheme是在Excel 3额外的列上创build:
- 年
- 月
- 天
值:
- =年份(A2)
- =月(A2)
- =日(A2)
(对于第2行,其中A是具有date的列)
然后使用这个function:
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
解决scheme鉴于提供的答案,新的toDateTime
看起来像这样:
let toDateTime (os:ObjectSeries<_>) = DateTime.Parse((os.Get "Date") :?> string)
你不能使用DateTime的构造函数,并给它一个string。
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