如何使用Excel';把日期当作钥匙?

如何使用Excel';把日期当作钥匙?,excel,dataframe,f#,deedle,Excel,Dataframe,F#,Deedle,假设给我一个列“Date”,其值如下所示: 1986年10月3日、1986年10月6日、1986年10月7日等 它不像执行Frame.indexRowsDate(“日期”)那样简单。 我当前的解决方案是在Excel中创建3个额外的列: 年 月 一天 价值观: =年份(A2) =月份(A2) =天(A2) (对于第2行,其中A是带有日期的列) 然后使用此功能: let toDateTime (os:ObjectSeries<_>) = let year = (os.Get

假设给我一个列“Date”,其值如下所示: 1986年10月3日、1986年10月6日、1986年10月7日等

它不像执行
Frame.indexRowsDate(“日期”)
那样简单。 我当前的解决方案是在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

不能对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

问题是什么?@robkuz我想知道是否有更好的方法,为什么单列方法不起作用?@robkuz或者Deedle正试图构建这样一个日期时间:DateTime(“03/10/86”),但这不是DateTime的有效构造函数,或者Deedle正在培训如何使用当天的Excel整数表示形式构造DateTime,这不符合DateTime的约定
let (success, date) = DateTime.TryParse("03/10/86")
if success then
   //use date here
else
   //do some error handling