Ordered Groupby Keys
See original GitHub issueThe current behavior of the xarray’s Groupby.groups
property provides a standard (unordered) dictionary. This is fine for most cases but leads to odd orderings in use cases like this one where I am using xarray’s FacetGrid plotting:
plot_kwargs = dict(col='season', vmin=15, vmax=35, levels=12, extend='both')
da_obs = ds_obs.SALT.isel(depth=0).groupby('time.season').mean('time')
da_obs.plot(**plot_kwargs)
Note that MAM and JJA are out of order.
I think this could be easily fixed by using an OrderedDict
in xarray.core.Groupby.groups
.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Can I sort the groupBy Collection keys? - Laracasts
Hi, I have a collection I wanted to group by a category, like so: $my_objects->groupBy(function ($item, $key) { if ($item->category) { return ...
Read more >Sorting LINQ 'GroupBy' operator keys into a custom order
In c#, when using the LINQ operator 'GroupBy' I would like to sort the keys into a specified custom ...
Read more >DOC: Order of groups in groupby and head method #17775
When sort = True is passed to groupby (which is by default) the groups will be in sorted order. If you loop through...
Read more >GroupBy key a sequence of ordered key values
I am working on haskell, under the hood I have a Seq that is a Vector, but a pseudocode solution is OK. I...
Read more >Pandas Groupby Sort within Groups - Spark by {Examples}
By using DataFrame.sort_values() , you can sort DataFrame in ascending or descending order, before you use this first group the DataFrame rows by...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I use
reindex
instead ofsortby
Just stumbled across this issue. Is there a recommended workaround?
I am usually doing this (specific to seasons):
Thought this might help some folks who need to solve this problem.