frictionlessdata / tableschema-go

A Go library for working with Table Schema.
MIT License
46 stars 10 forks source link

schema.EncodeNumericColumn? #65

Closed danielfireman closed 5 years ago

danielfireman commented 6 years ago

Hi @roll , @akariv @pwalsh

I would like to start doing some math with data from my tables. As gonum already provides a lot of functionality to deal with numbers, I would like to make it easier for tableschema users to use it. More precisely, I would like something along those lines of:

tab, err := csv.FromFile("mydata")
if err != nil {
  panic(err)
}
age, err schema.EncodeNumericColumns(tab, "age")
if err != nil {
   panic(err)
}
mean := stat.Mean(ages, nil)
variance := stat.Variance(age, nil)
stddev := math.Sqrt(variance)
fmt.Printf("mean:%f var:%f stddev:%f", mean, variance, stddev)

The reason why I am focusing on numeric is that I would like that to be performant (meaning not a lot of use of reflection) and more readable (avoid casting all over the place).

What do you guys think?

danielfireman commented 5 years ago

The things have changed and I believe we should go for `CastColumn (totally inspired by CastRow).

tab, err := csv.FromFile("mydata")
if err != nil {
  panic(err)
}
var age []int64
if err := schema.CastColumn(tab, "age"); err != nil {
   panic(err)
}
mean := stat.Mean(ages, nil)
variance := stat.Variance(age, nil)
stddev := math.Sqrt(variance)
fmt.Printf("mean:%f var:%f stddev:%f", mean, variance, stddev)
danielfireman commented 5 years ago

Fixed by #80

roll commented 5 years ago

Sorry I missed it. It's great!