go-gota / gota

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

Is there a way to transform DataFrame to user customer struct? #192

Open liracle opened 1 year ago

liracle commented 1 year ago

I want something like json.Unmarshal , code like this

type People struct {
    Name string `dataframe:"name"`
    Age  int    `dateframe:"age"`
    Male bool   `dateframe:"male"`
}
df := dataframe.LoadRecords(
    [][]string{
        []string{"name", "age", "male"},
        []string{"Cloris", "24", "false"},
        []string{"Ben", "55", "true"},
    },
    dataframe.DetectTypes(false),
    dataframe.DefaultType(series.String),
    dataframe.WithTypes(map[string]series.Type{
        "age":  series.Int,
        "male": series.Bool,
    }),
)
var peoples []People
df.Unmarshal(&peoples)

and will get peoples output:

// peoples
// People{Name:"Cloris", Age:24, "Male":false}
// People{Name:"Ben", Age:55, "Male":true}
liracle commented 1 year ago

In my way, now i use mapstructure implement this, but i think it should be built-in function

liracle commented 1 year ago

I want contribute my code. Is this repository being maintained now?

stkrzysiak commented 1 year ago

I'm not sure if it's maintained much, github insights seems to only show a month, thought it was more in the past. Last merge was October 10th, with a whopping PR outstanding #180 from March of this year. Seems like the pushback was how big the PR was and no issue describing the need. Maybe if you PR you'll get a merge. I'm curious, would you bring mapstructure into this repo or do a similar approach w/o using mapstructure?