2

I have a dataframe df that has two columns, i.e. A and B. I am trying to create a new column and adding it to the df like below:

logFunc := func(s series.Series) series.Series {
    floats := s.Float()
    outCol := []float64 {}
    for _, f := range floats {
        outCol = append(outCol, math.Ceil(1 - math.Log(f)))
    }
    return series.Floats(outCol)
}

newCol := df.Select("B").rapply(logFunc)

newDF := df.mutate(Series.New(newCol, series.Float, "C")
fmt.Println(newDF)

But I am getting the below error:

DataFrame error: mutate: wrong dimensions

Any help in this regard will be wonderful. Thanks

When I checked through the code of Gota and found this:

func (df DataFrame) Mutate(s series.Series) DataFrame {
        ...

    if s.Len() != df.nrows {
        return DataFrame{Err: fmt.Errorf("mutate: wrong dimensions")}
    }

This means that if the length of the series and nrows of df doesn't match, it throws this error. But the way I am building this, they should match. Not sure how this can be solved.

I am expecting the newDF to have the new column alongside others.

Edit:

I figured out the issue here. The output of logFunc is not series but a dataframe. Now the question is how can we get the series out of the dataframe.

Axas
  • 21
  • 3

0 Answers0