Home > OS >  Setting column names in gota
Setting column names in gota

Time:03-03

I have a dataset without column names defined. How can I assign these programmatically using gota? For comparison, Pandas has df.rename.

Say my data looks like this:

1,2,3
4,5,6
7,8,9

I basically want this in my dataframe:

A,B,C
1,2,3
4,5,6
7,8,9

CodePudding user response:

You can call ReadCSV with load options. In go, this method is called functional options.

This is the example in gota:

func main() {
    f, err := os.Open("sample2.csv")
    if err != nil {
        panic(err.Error())
    }
    defer f.Close()

    names := dataframe.Names("A", "B", "C")
    noHeader := dataframe.HasHeader(false)

    df := dataframe.ReadCSV(f, names, noHeader)
    r := df.Records()

    fmt.Println(r)
}

Functions Load* and Read* in gota all have LoadOption:
https://pkg.go.dev/github.com/go-gota/gota/dataframe

  • Related