go-gota / gota

Gota: DataFrames and data wrangling in Go (Golang)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

dataframe.GroupBy function will trim the prefix '0' characters in a number string

prliu opened this issue · comments

The new dataframe.GroupBy function will trim the prefix '0' characters in a number string, for example, '0050'.

This is my sample data:

SID,COUNT
0050,100
0050,150
0051,20
0051,30
YY0050,30

I try to process SUM operation on COUNT column, and group by SID column. Following is my code:

type CSVRecord struct {
	Sid   string
	Count int
}

var raw []CSVRecord

//
// do something to load CSV into raw variable ...
//

df := dataframe.LoadStructs(raw)
fmt.Println(raw)

It is cool...

[5x2] DataFrame

    Sid      Count
 0: 0050     100  
 1: 0050     150  
 2: 0051     20   
 3: 0051     30   
 4: YY0050   30   
    <string> <int>

than I try to run SUM operation, and group the result by SID...

groups := df.GroupBy("Sid")
aggre := groups.Aggregation(
	[]dataframe.AggregationType{dataframe.Aggregation_SUM},
	[]string{"Count"})
fmt.Println(aggre)

I expect the result as below:

[3x2] DataFrame

    Count_SUM Sid     
 0: 250       0050      
 1: 50        0051      
 2: 30        YY0050  
    <int>     <string>

But I got a result like this:

[3x2] DataFrame

    Count_SUM Sid     
 0: 250       50      
 1: 50        51      
 2: 30        YY0050  
    <int>     <string>

As you can see, the prefix '0' in string '0050' has been trimmed.