xarray.core.accessor_dt.DatetimeAccessor¶
-
class
xarray.core.accessor_dt.DatetimeAccessor(obj)¶ Access datetime fields for DataArrays with datetime-like dtypes.
Similar to pandas, fields can be accessed through the .dt attribute for applicable DataArrays:
>>> ds = xarray.Dataset({'time': pd.date_range(start='2000/01/01', ... freq='D', periods=100)}) >>> ds.time.dt <xarray.core.accessors.DatetimeAccessor at 0x10c369f60> >>> ds.time.dt.dayofyear[:5] <xarray.DataArray 'dayofyear' (time: 5)> array([1, 2, 3, 4, 5], dtype=int32) Coordinates: * time (time) datetime64[ns] 2000-01-01 2000-01-02 2000-01-03 ...
All of the pandas fields are accessible here. Note that these fields are not calendar-aware; if your datetimes are encoded with a non-Gregorian calendar (e.g. a 360-day calendar) using cftime, then some fields like dayofyear may not be accurate.
-
__init__(obj)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__(obj)Initialize self. ceil(freq)Round timestamps upward to specified frequency resolution. floor(freq)Round timestamps downward to specified frequency resolution. round(freq)Round timestamps to specified frequency resolution. strftime(date_format)Return an array of formatted strings specified by date_format, which supports the same string format as the python standard library. Attributes
dayThe days of the datetime dayofweekThe day of the week with Monday=0, Sunday=6 dayofyearThe ordinal day of the year days_in_monthThe number of days in the month daysinmonthThe number of days in the month hourThe hours of the datetime microsecondThe microseconds of the datetime minuteThe minutes of the datetime monthThe month as January=1, December=12 nanosecondThe nanoseconds of the datetime quarterThe quarter of the date seasonDJF) secondThe seconds of the datetime timeTimestamps corresponding to datetimes weekThe week ordinal of the year weekdayThe day of the week with Monday=0, Sunday=6 weekday_nameFriday) weekofyearThe week ordinal of the year yearThe year of the datetime -