Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Go gota Dataframe not loading struct, requires []struct

I am reading a file with each row containing two words separated by a space. I scan and split each line to two words (strings) and store them in the MyEntity struct (in items). The words are then added to 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)

...

Should items not be a []struct here? I am using the gota package (https://github.com/go-gota/gota) to create a DataFrame from items but using dataframe.LoadStructs(items) fails because items is a struct and it must be a []struct.

I am fairly new to Go, so what am I missing here?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Load the data frame from the slice of entities:

 df := dataframe.LoadStructs(items.Entities)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading