fslaborg / zzarchive-FsLab

A collection of packages for data science with F#
http://fslab.org
Other
159 stars 42 forks source link

Expression evaluation failed: Input string was not in a correct format. #147

Closed ykafia closed 5 years ago

ykafia commented 5 years ago

I tried using fslab with ifSharp ( ipython notebooks for fsharp)

I loaded a sample train dataset containing numbers and DateTimes.

open Deedle
let kaggle = Frame.ReadCsv("./dataset/trainS.csv", inferTypes= true)
kaggle?click_time 
//the last line is supposed to give an output of the data, it works with the int32 columns but not the datetime ones

I got an Expression evaluation failed and don't know if i did something wrong since i'm new to fsharp

Error below :

Expression evaluation failed: Invalid cast from 'DateTime' to 'Double'.
InvalidCastExceptionInvalid cast from 'DateTime' to 'Double'.
   at System.DateTime.System.IConvertible.ToDouble(IFormatProvider provider)
   at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider)
   at Deedle.Internal.Convert.convertType[T](ConversionKind conversionKind, Object value) in C:\code\deedle\src\Deedle\Common\Common.fs:line 1430
   at Deedle.VectorHelpers.convertType@274-3.Invoke(T value) in C:\code\deedle\src\Deedle\Vectors\VectorHelpers.fs:line 274
   at Deedle.F# Vector extensions (core).IVector-1-Select@127.Invoke(IVectorLocation _arg1, OptionalValue`1 input)
   at <StartupCode$Deedle>.$ArrayVector.data@374-6.Invoke(Int32 i, T v) in C:\code\deedle\src\Deedle\Vectors\ArrayVector.fs:line 374
   at Microsoft.FSharp.Collections.ArrayModule.MapIndexed[T,TResult](FSharpFunc`2 mapping, T[] array)
   at Deedle.Vectors.ArrayVector.ArrayVector`1.Deedle-IVector`1-Select[TNewValue](FSharpFunc`2 f) in C:\code\deedle\src\Deedle\Vectors\ArrayVector.fs:line 374
   at Deedle.Frame`2.GetColumn[R](TColumnKey column, Lookup lookup) in C:\code\deedle\src\Deedle\Frame.fs:line 898
   at <StartupCode$FSI_0039>.$FSI_0039.main@()
zyzhu commented 5 years ago

The ? operator was a shortcut to get a column in float.

For this column, you need to run kaggle.Columns.["click_time"].As<DateTime>()

ykafia commented 5 years ago

This worked, I'll have to read more about F# in the future, thank you for your time! @zyzhu