How do I reshape longitude data in an xarray of nc files

Viewed 22

The current format of the longitude data is in the form (0,360) as shown in the picture. I want to get it to be (-180,180) where (-180,0) is equal to (180,360).

code image

1 Answers

Assuming you have a column of longitude data (it's hard to tell from your sample), something like this should work:

pick = pd['longitude']>180
pd.loc[pick,'longitude'] = pd.loc[pick,'longitude'] - 360

The first line chooses the rows where longitude needs adjusting. The second line does the math for only those rows.

Related