• <i id='KzQ87'><tr id='KzQ87'><dt id='KzQ87'><q id='KzQ87'><span id='KzQ87'><b id='KzQ87'><form id='KzQ87'><ins id='KzQ87'></ins><ul id='KzQ87'></ul><sub id='KzQ87'></sub></form><legend id='KzQ87'></legend><bdo id='KzQ87'><pre id='KzQ87'><center id='KzQ87'></center></pre></bdo></b><th id='KzQ87'></th></span></q></dt></tr></i><div id='KzQ87'><tfoot id='KzQ87'></tfoot><dl id='KzQ87'><fieldset id='KzQ87'></fieldset></dl></div>

    <small id='KzQ87'></small><noframes id='KzQ87'>

      <tfoot id='KzQ87'></tfoot>

    1. <legend id='KzQ87'><style id='KzQ87'><dir id='KzQ87'><q id='KzQ87'></q></dir></style></legend>

        • <bdo id='KzQ87'></bdo><ul id='KzQ87'></ul>

        在xarray中按单个维度的多个坐标分组

        groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
        1. <tfoot id='DFnDL'></tfoot>

            <small id='DFnDL'></small><noframes id='DFnDL'>

                  <bdo id='DFnDL'></bdo><ul id='DFnDL'></ul>

                    <tbody id='DFnDL'></tbody>
                  <legend id='DFnDL'><style id='DFnDL'><dir id='DFnDL'><q id='DFnDL'></q></dir></style></legend>
                  <i id='DFnDL'><tr id='DFnDL'><dt id='DFnDL'><q id='DFnDL'><span id='DFnDL'><b id='DFnDL'><form id='DFnDL'><ins id='DFnDL'></ins><ul id='DFnDL'></ul><sub id='DFnDL'></sub></form><legend id='DFnDL'></legend><bdo id='DFnDL'><pre id='DFnDL'><center id='DFnDL'></center></pre></bdo></b><th id='DFnDL'></th></span></q></dt></tr></i><div id='DFnDL'><tfoot id='DFnDL'></tfoot><dl id='DFnDL'><fieldset id='DFnDL'></fieldset></dl></div>
                • 本文介绍了在xarray中按单个维度的多个坐标分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个沿一维具有多个坐标的xarray。在下面的示例中,坐标ab是沿着维度dim1定义的。我如何groupby使用沿相同维度定义的两个坐标?与this question不同,我不是尝试沿着不同的维度分组,而是沿着单个维度进行分组。

                  import xarray as xr
                  
                  d = xr.DataArray([[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]],
                      coords={
                          'a': ('dim1',['A', 'A', 'B', 'B']),
                          'b': ('dim1',['1', '2', '1', '2']),
                          'c': ('dim2',['x', 'y', 'z'])
                      },
                      dims=['dim1', 'dim2'])
                  d.groupby(['a','b']) # this gives: TypeError: `group` must be an xarray.DataArray or the name of an xarray variable or dimension
                  

                  推荐答案

                  这是我当前的解决方法:

                  import numpy as np
                  import xarray as xr
                  
                  def groupby_multicoords(da, fields):
                      common_dim = da.coords[fields[0]].dims[0]
                      tups_arr = np.empty(len(da[common_dim]), dtype=object)
                      tups_arr[:] = list(zip(*(da[f].values for f in fields)))
                      return da.assign_coords(grouping_zip=xr.DataArray(tups_arr, dims=common_dim)).groupby('grouping_zip')
                  

                  然后groupby_multicoords(da=d, fields=['a', 'b'])

                  但是,在分组之后,我仍然使用"grouping_zip"坐标。如将其替换为d.groupby(['a','b'])..

                  ,我将不胜感激

                  这篇关于在xarray中按单个维度的多个坐标分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                  <tfoot id='PWd2e'></tfoot>
                  <i id='PWd2e'><tr id='PWd2e'><dt id='PWd2e'><q id='PWd2e'><span id='PWd2e'><b id='PWd2e'><form id='PWd2e'><ins id='PWd2e'></ins><ul id='PWd2e'></ul><sub id='PWd2e'></sub></form><legend id='PWd2e'></legend><bdo id='PWd2e'><pre id='PWd2e'><center id='PWd2e'></center></pre></bdo></b><th id='PWd2e'></th></span></q></dt></tr></i><div id='PWd2e'><tfoot id='PWd2e'></tfoot><dl id='PWd2e'><fieldset id='PWd2e'></fieldset></dl></div>

                      • <legend id='PWd2e'><style id='PWd2e'><dir id='PWd2e'><q id='PWd2e'></q></dir></style></legend>

                        • <bdo id='PWd2e'></bdo><ul id='PWd2e'></ul>

                            <small id='PWd2e'></small><noframes id='PWd2e'>

                              <tbody id='PWd2e'></tbody>