Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Difficult to convert pd.DataFrame to Dataset with multi-index #8794

Closed
staadecker opened this issue Feb 28, 2024 · 2 comments · Fixed by #8817
Closed

Difficult to convert pd.DataFrame to Dataset with multi-index #8794

staadecker opened this issue Feb 28, 2024 · 2 comments · Fixed by #8817
Labels
needs triage Issue that has not been reviewed by xarray team member

Comments

@staadecker
Copy link
Contributor

What is your issue?

No direct way to create multi-index dataset

Unless I'm missing something, there is no easy way to convert a Pandas dataframe to a dataset with a multi-index. For example, xr.Dataset.from_dataframe automatically converts any Pandas multi-index into separate dimensions.

Workaround is inefficient

One workaround is doing xr.Dataset.from_dataframe(df).stack(...) however this is very inefficient for sparse multi-indices.

@staadecker staadecker added the needs triage Issue that has not been reviewed by xarray team member label Feb 28, 2024
@max-sixty
Copy link
Collaborator

Does xr.Dataset(df) work?

@staadecker
Copy link
Contributor Author

@max-sixty yes it does. Thank you! I submitted a pull request to add this to the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue that has not been reviewed by xarray team member
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants