Skip to content

How do I remove all unused coordinates? #7465

Answered by TomNicholas
cmdupuis3 asked this question in Q&A
Discussion options

You must be logged in to vote

Coordinates are not "used" by data variables, so I'm not entirely sure what you mean.

Variables depend on dimensions, but coordinates are a separate special set of variables. Coordinates may have the same name as dimensions though, and if they are one-dimensional they are referred to as "dimension coordinates". I appreciate that that is confusing.

If you just want to remove all the coordinates that aren't dimension coordinates, you could do

ds.drop_vars([var for var in ds.coords if var not in ds.dims])

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by cmdupuis3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants