home / github / issue_comments

Menu
  • GraphQL API
  • Search all tables

issue_comments: 499248139

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions performed_via_github_app issue
https://github.com/pydata/xarray/issues/2933#issuecomment-499248139 https://api.github.com/repos/pydata/xarray/issues/2933 499248139 MDEyOklzc3VlQ29tbWVudDQ5OTI0ODEzOQ== 3621629 2019-06-05T20:44:29Z 2019-06-05T20:44:29Z CONTRIBUTOR

Hello @ray306

stack/unstack in xarray is a bit different from pandas mechanics.

  • From the stack docstring ``` Stack any number of existing dimensions into a single new dimension.

New dimensions will be added at the end, and the corresponding coordinate variables will be combined into a MultiIndex. `` Breaking it down,da.stack({'index': ['variable']})fails because it's trying to: 1. create a new multi-index with a single level inside (variable) [so far so good but probably not what you had in mind] 2. add a new dimension named 'index' with coordinates given by the newly created index. This part yields the error you saw sincedaalready has an index namedindex`.

To mesh the variable dimension into the index dimension, you first need to unstack it: python da.unstack('index').stack(index=('first', 'second', 'variable'))

  • From the unstack docstring ``` Unstack existing dimensions corresponding to MultiIndexes into multiple new dimensions.

Parameters

dim : str or sequence of str, optional Dimension(s) over which to unstack. By default unstacks all MultiIndexes. `` Yourdaarray only has two dimensions:variableandindex. That's why you can'tda.unstack('first').first` is a coordinate (along the dimension 'index') not a dimension.

You could use da.unstack('index').stack(index=['second']) but this is somehow the same thing as da.unstack() since a multi-index with a single level is totally equivalent to the level itself.

I hope this helps you enjoy xarray and use it more.

{
    "total_count": 1,
    "+1": 1,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
  438947247
Powered by Datasette · Queries took 0.622ms · About: xarray-datasette