go-gota / gota

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

Allow numeric column-index for filters #106

Closed typeless closed 4 years ago

typeless commented 4 years ago

When the column names are not available, we should be able to use a number to index the column.

kniren commented 4 years ago

I am surprised this was not already in there. In any case, I'm currently considering PR #99, which changes the filtering code. I'm putting this issue on hold until that is resolved, but not closing it yet.

kniren commented 4 years ago

99 Is merged. Do you still think we need this feature?

typeless commented 4 years ago

I want to clean the data and set the column names like the following:

        hdr := df.Filter(
            dataframe.F{
                Colidx:     0,
                Comparator: series.Eq,
                Comparando: "Company ID",
            },
        ).Filter(
            dataframe.F{
                Colidx:     2,
                Comparator: series.Eq,
                Comparando: "Current month revenue",
            },
        ).Records()

        if err := df.SetNames(hdr[1]...); err != nil {
            log.Fatal(err)
        }

The input table has a multi-row header and only one of the rows is what I need. Since there is no sensible column names before the cleansing. I cannot use the column names as the filter condition either. I think what this PR adds is quite ad-hoc. I'd like to have some better solution. 😆

kniren commented 4 years ago

Merged, thanks!

If you still think there is a better implementation, feel free to try and improve it, but If you really need this, I'm OK with it.