登录
首页 >  Golang >  Go问答

获取未加载结构的数据框,请提供结构

来源:stackoverflow

时间:2024-02-10 20:09:21 234浏览 收藏

“纵有疾风来,人生不言弃”,这句话送给正在学习Golang的朋友们,也希望在阅读本文《获取未加载结构的数据框,请提供结构》后,能够真的帮助到大家。我也会在后续的文章中,陆续更新Golang相关的技术文章,有好的建议欢迎大家在评论留言,非常感谢!

问题内容

我正在读取一个文件,每行包含两个用空格分隔的单词。我扫描每一行并将其拆分为两个单词(字符串),并将它们存储在 myentity 结构中(在 items 中)。然后将这些单词添加到 items

type Entity struct {
    Name string
    Entity string 
}

type MyEntity struct {
    Entities []Entity
}

func (entity *MyEntity) AddEntity(item Entity) []Entity {
    entity.Entities = append(entity.Entities, item)
    return entity.Entities
}

...

items := MyEntity{}

// loop here over the rows - name is first word, entity is second word

item := Entity{
    name, entity,
}

items.AddEntity(item)

...

items 不应该是 []struct 吗?我正在使用 gota 包(https://github.com/go-gota/gota)从 items 创建 dataframe 但使用 dataframe.loadstructs(items) 失败,因为 itemsstruct 并且它必须是 zqbcz qb[]结构。

我对 go 还很陌生,那么我在这里错过了什么?


正确答案


从实体切片加载数据框:

df := dataframe.LoadStructs(items.Entities)

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>