rocketlaunchr / dataframe-go

DataFrames for Go: For statistics, machine-learning, and data manipulation/exploration
Other
1.16k stars 93 forks source link

undefined: dataframe.LoadFromCSV #45

Closed andrewm4894 closed 3 years ago

andrewm4894 commented 3 years ago

When i run the below example to read in a df from a dummy string i get the below errors:

➜  learn-go git:(main) ✗ go run dev.go
# command-line-arguments
./dev.go:21:13: undefined: dataframe.LoadFromCSV
./dev.go:21:65: undefined: dataframe.CSVLoadOptions

package main

import (
    "context"
    "fmt"
    "strings"

    imports "github.com/rocketlaunchr/dataframe-go"
)

func main() {

    csvStr := `colA,colB
    1,"First"
    2,"Second"
    3,"Third"
    4,"Fourth"`

    ctx := context.Background()

    df, err := imports.LoadFromCSV(ctx, strings.NewReader(csvStr), imports.CSVLoadOptions{
        DictateDataType: map[string]interface{}{
            "colA": int64(0),
            "colB": "",
        },
    })

    fmt.Println(err)
    fmt.Println(df)

}

I'm not really sure what i'm doing wrong here. Was trying to use example from this sort of approach: https://github.com/rocketlaunchr/dataframe-go/blob/master/imports/infer_test.go

Here is the output of go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/andre/.cache/go-build"
GOENV="/home/andre/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/andre/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/andre/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build868960458=/tmp/go-build -gno-record-gcc-switches"

p.s. i'm new to Go so pretty sure it could be me doing something silly :)

pjebs commented 3 years ago

Your CSV string is not valid. In order to make it look nice, you've added tabs/spaces at the start of each line

pjebs commented 3 years ago

Format it to look like the one in example or read from a CSV file

pjebs commented 3 years ago

imports "github.com/rocketlaunchr/dataframe-go/imports"

pjebs commented 3 years ago

Import path is not correct

andrewm4894 commented 3 years ago

Thank you - working code below:

package main

import (
    "context"
    "fmt"
    "strings"

    imports "github.com/rocketlaunchr/dataframe-go/imports"
)

func main() {

    csvStr := `
colA,colB
1,"First"
2,"Second"
3,"Third"
4,"Fourth"`

    ctx := context.Background()

    df, err := imports.LoadFromCSV(ctx, strings.NewReader(csvStr), imports.CSVLoadOptions{
        DictateDataType: map[string]interface{}{
            "colA": int64(0),
            "colB": "",
        },
    })

    fmt.Println(err)
    fmt.Println(df)

}