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

在使用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)

图片转代码服务由CSDN问答提供 功能建议

我正在尝试找出如何在中使用 dataframe.LoadOptions href =“ https://github.com/kniren/gota” rel =“ nofollow noreferrer”> gota库,用于在读取CSV文件时指定分隔符。

 包main 
 
import(
“ fmt” 
“ github.com/kniren/gota/dataframe"
” io / ioutil“ 
”字符串 “ 
)
 
func main(){
 content,_:= ioutil.ReadFile(” / path / to / csv / file.csv“)
 ioContent:= strings.NewReader(string(content))  
 
 df:=数据框。ReadCSV(ioContent)
 
 fmt.Println(df)
} 
   
 
 

dataframe.ReadCSV函数需要一个 * dataframe.LoadOptions

类型的 options 变量我检查了dataframe.LoadOptions结构的定义,并发现了以下内容: < pre> type LoadOption func(* loadOptions) type loadOptions struct { defaultType series.Type detectTypes bool hasHeader bool 名称[] string nanValues [] string 分隔符符文\ n个类型map [string] series.Type }

我是Go的新手,对此一无所知。 第一次遇到这样的定义:键入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.
    )
    
    点赞 打赏 评论

相关推荐 更多相似问题