xarray.CFTimeIndex.to_datetimeindex#
- CFTimeIndex.to_datetimeindex(unsafe=False, time_unit=None)[source]#
If possible, convert this index to a pandas.DatetimeIndex.
- Parameters:
- Returns:
- Raises:
ValueError – If the CFTimeIndex contains dates that are not possible in the standard calendar or outside the range representable by the specified
time_unit
.- Warns:
RuntimeWarning – If converting from a non-standard calendar, or a Gregorian calendar with dates prior to the reform (1582-10-15).
Warning
Note that for non-proleptic Gregorian calendars, this will change the calendar type of the index. In that case the result of this method should be used with caution.
Examples
>>> times = xr.cftime_range("2000", periods=2, calendar="gregorian") >>> times CFTimeIndex([2000-01-01 00:00:00, 2000-01-02 00:00:00], dtype='object', length=2, calendar='standard', freq=None) >>> times.to_datetimeindex(time_unit="ns") DatetimeIndex(['2000-01-01', '2000-01-02'], dtype='datetime64[ns]', freq=None)