down2323 2018-04-08 05:18
浏览 1302
已采纳

在使用dataframe.ReadCSV时指定分隔符

I'm trying to figure out how to use dataframe.LoadOptions in the gota library to specify a delimiter when reading the CSV file.

package main

import (
    "fmt"
    "github.com/kniren/gota/dataframe"
    "io/ioutil"
    "strings"
)

func main() {
    content, _ := ioutil.ReadFile("/path/to/csv/file.csv")
    ioContent := strings.NewReader(string(content))

    df := dataframe.ReadCSV(ioContent)

    fmt.Println(df)
}

The dataframe.ReadCSV function takes an options variable of type *dataframe.LoadOptions

I checked the definition for the dataframe.LoadOptions struct and found the following:

type LoadOption func(*loadOptions)

type loadOptions struct {
    defaultType series.Type
    detectTypes bool
    hasHeader bool
    names []string
    nanValues []string
    delimiter rune
    types map[string]series.Type
}

I'm new to Go and got stuck on this. First time I've come across a definition like this: type LoadOption func(*loadOptions)

  • 写回答

1条回答 默认 最新

  • dongtangxi1584 2018-04-08 10:33
    关注

    This library uses functional options.

    dataframe.ReadCSV takes any number of dataframe.LoadOption, where LoadOption is a function type. Look through the docs for things that return a value of LoadOption and pass those to ReadCSV:

    dataframe.ReadCSV(ioContent,
        dataframe.WithDelimiter(';'),
        dataframe.HasHeader(true),
        // etc.
    )
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制