go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)
Other
2.98k stars 276 forks source link

How to filter out NaN rows? #157

Closed denghejun closed 3 years ago

denghejun commented 3 years ago

How to filter out NaN rows?

filteredDF := dfLeftJoin.Filter(dataframe.F{
        Colname:    "primary_tag",
        Comparator: series.Eq,
        Comparando: "", // "", "NaN", "null", "NULL", all of them don't work
    })
ryanpiaskowy commented 2 years ago

In case others come across this question, this is how I accomplished it in my project:

Created a function to return the filter function for only NaNs:

func IsNaNFilter() func() func(el series.Element) bool {
    isNaNFunction := func() func(el series.Element) bool {
        return func(el series.Element) bool {
            return el.IsNA()
        }
    }
    return isNaNFunction
}

Then whenever I need to filter to only rows that the value is NaN, I do this:

isNaN := IsNaNFilter()
out = out.Filter(dataframe.F{
        Colname:    "ColName",
        Comparator: series.CompFunc,
        Comparando: isNaN()})