go-gota / gota

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

custom sort? #67

Open dtenenba opened 6 years ago

dtenenba commented 6 years ago

What's the easiest way to do a custom sort of a dataframe? For example, I have a column with string values like 10/04/2014 04:10:10 p.m. and I would like to sort them by the date that represents (ascending).

If this is not easily possible, consider this a feature request. Thanks for a useful package.

kmrx commented 6 years ago

Hi @dtenenba,

Adding support for more types has been brought up earlier. Please see this thread https://github.com/kniren/gota/pull/27

Since above is not yet available. If I were to do the custom sort, my quick and dirty way would be to -

range over df.Col("mytimecolumn").Records() converting the value to time.Time and sorting the resultant array. Then use maps to create a new dataframe that is sorted the way you need.

This solution of course does not keep in mind that your data set has duplicate rows in "mytimecolumn".

Thanks to kniren.