Closed patgunner closed 4 years ago
For gonum use only *SeriesFloat64. You can then access .Values
field.
That is a []float64
You can type assert series interface to *SeriesFloat64
providing the underlying is actually a SeriesFloat64
s1 := dataframe.NewSeriesInt64("day", nil, 1, 2, 3, 4, 5, 6, 7, 8)
s2 := dataframe.NewSeriesFloat64("sales", nil, 50.3, 23.4, 56.2, nil, nil, 84.2, 72, 89)
df := dataframe.NewDataFrame(s1, s2)
df.Series[2].(*dataframe.SeriesFloat64).Values // []float64 for use with gonum
or df.Series[df.MustNameToColumn("sales")].Values
Thanks @pjebs . That worked for me. One other small input I wanted for the following scenario.
If I have an input in the form of []interface{} and I want to add this to a SeriesFloat64/SeriesInt64 series, would there be some easy way to achieve this?
This is in continuation to as you mentioned "For gonum use only *SeriesFloat64". :)
var vals []interface{}
dataframe.NewSeriesFloat64("x", nil, vals...) // when creating new series
But it doesn't seem like you can insert slice of interface into an existing Series.
But the underlying problem is your data should not be in []interface{}
I wanted to know if there is a way to convert a series interface to get the original type of series (Float64/Int64/Mixed) underneath it. I will describe mu use case.
After creating a dataframe, I am trying to use gonum to do some analysis. For eg. linear regression of two series from dataframe. But for this I have to iterate over the whole series(using ValuesIterator) to get back each element into a []float64, which is required by gonum. ToSeriesFloat64 does not help since it is not implemented by Series.
Is there an easier way to access the whole underlying series into into corresponding concrete slice?