How can I only keep data in one xarray for entries that match a specific dimension in another xarray? #7567
-
I have two datasets: The time in ds1 has a higher resolution than ds2 and all the times in ds2 are present in ds1. For instance:
(I am using int instead of datetime64 here for the readability) I would like to drop all the entries in ds1 where the time is NOT in ds2.time so that I only keep the records in ds1 such as: How can I do that? I tried sel, isel, resample, where... All failed. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
if I understand correctly, you should be able to do If that doesn't work, maybe your times are a little bit off? Try Otherwise we'd need more information on your time variable and the code you tried. |
Beta Was this translation helpful? Give feedback.
After a lot of research, trial and error, I got it to work as follow:
ds1 = ds1.where(ds1.time.isin(ds2.time), drop=True)