pydata / pydata/xarray

Explanation of full DataFrame to Dataset translation

Open
#3,873 4 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

topic-documentation
Dominant language
Python
Stars
4.2k
Forks
1.4k
Avg merge
2d 15h
Merged PRs (30d)
14

Description

Using to_xarray() on a DataFrame doesn't get me to the Dataset I want, because typically I want some of the DataFrame's columns to be coordinates, and some Data Variables.

This Stack Exchange question and answer give part of the solution: https://stackoverflow.com/questions/59672658/reassigning-xarray-data-variable-to-xarray-coordinate

This tells us how to turn some of the data variables in the translated data set into coordinates. But that's not the full solution, because we also need the coordinates to be applied to the data variables. Somehow we need to add the variables that are now coordinates as dimensions.

This is probably somewhere in the docs, but it isn't pulled together into a big picture answer. It would be great if there was an end-to-end example of taking a pandas DataFrame, partitioning variables into coordinates and data variables, and being able to use the resulting coordinates (with Dataset.sel()) to address the data variables.

If that is in the online docs, I don't know how to find it. Thanks!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the existing documentation for pandas DataFrame.to_xarray(), Dataset coordinates, dimensions, and Dataset.sel(), using the linked Stack Exchange question as context. Done means an end-to-end example shows how to partition DataFrame columns into coordinates and data variables, apply those coordinates to the data variables, and select them with Dataset.sel().

Written by the indexing model from the issue text.

Assessment

Tech stack
pandas, python
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.