go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to filter out NaN rows?

denghejun opened this issue · comments

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
	})

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()})