go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)
Other
2.98k stars 276 forks source link

Question: update all values(zero padding) #160

Open coldmu opened 2 years ago

coldmu commented 2 years ago
I want to fill zero-padding. It is not easy to update all values. Could you help it? plz...     (Before) df: col1 col2
123 Paul
33 Jane
(After) df: col1 col2
000123 Paul
000033 Jane

thank you :)

coldmu commented 2 years ago

I try to use series.Map().

sel2 := sel1.Col("col1")

zeroFill := func(e series.Element) series.Element {
        result := e.Copy()
        zeroResult := fmt.Sprintf("%06s", result.String())
        result.Set(zeroResult)
        return series.Element(result)
    }

received := sel2.Map(zeroFill)

But I got other problems.. how to change series type. When I update values, it was removed 0. Because it is still int type...

coldmu commented 2 years ago

I found a solution!! When I got data, I can handle data type with options.

Like this: cs = dataframe.ReadHTML(strings.NewReader(htmlUTF8), dataframe.DetectTypes(false), dataframe.DefaultType(series.String))[0]

But I'm still curious how to change series type.

chrmang commented 2 years ago

Hi coldmu, it seems to be an unsolved point.