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

在使用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 </ code> href =“ https://github.com/kniren/gota” rel =“ nofollow noreferrer”> gota库,用于在读取CSV文件时指定分隔符。 </ p>

 包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)
} 
 </ code> </ pre> 
 
 

dataframe.ReadCSV函数需要一个 * dataframe.LoadOptions </ p>

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

我是Go的新手,对此一无所知。 第一次遇到这样的定义:键入LoadOption func(* loadOptions)</ code> </ p> </ div>

1条回答 默认 最新

相关推荐 更多相似问题