0

I have an xarray dataset with foll. structure:

<xarray.Dataset>
Dimensions:           (N: 5, latitude: 360, longitude: 720, time: 27)
Coordinates:
  * latitude          (latitude) float64 89.75 89.25 88.75 88.25 87.75 87.25 ...
  * longitude         (longitude) float64 -179.8 -179.2 -178.8 -178.2 -177.8 ...
  * time              (time) float64 0.0 1.826e+03 3.652e+03 5.479e+03 ...
  * N                 (N) |S1 '1' '2' '3' '4' '5'

I want to copy a handle to this dataset and remove the coordinated named 'N'.

When I do this:

new_nc = hndl_nc.copy() 
new_nc.drop('N')

Subsequently, when I try to assign data to new variable in new_nc, it does not work:

new_nc['new_var'] = ...

How do I fix this?

1 Answer 1

1

drop, like most xarray methods, returns a new xarray object rather than modifying the orginal object in-place. So instead you should write new_nc = hdnl_nc.drop('N').

Alternatively, you could Python's del keyword: del new_nc['N']

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.