How do I remove all unused coordinates? #7465
-
I have an xarray dataset. It has about 50 different coordinates, and I'm only using three of them max. How do I remove all the coordinates that aren't used by any data arrays? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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]) |
Beta Was this translation helpful? Give feedback.
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