Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DatetimeIndex#

classpandas.DatetimeIndex(data=None,freq=<no_default>,tz=<no_default>,normalize=<no_default>,closed=<no_default>,ambiguous='raise',dayfirst=False,yearfirst=False,dtype=None,copy=False,name=None)[source]#

Immutable ndarray-like of datetime64 data.

Represented internally as int64, and which can be boxed to Timestamp objectsthat are subclasses of datetime and carry metadata.

Changed in version 2.0.0:The various numeric date/time attributes (day,month,year etc.) now have dtypeint32. Previously they had dtypeint64.

Parameters:
dataarray-like (1-dimensional)

Datetime-like data to construct index with.

freqstr or pandas offset object, optional

One of pandas date offset strings or corresponding objects. The string‘infer’ can be passed in order to set the frequency of the index as theinferred frequency upon creation.

tzpytz.timezone or dateutil.tz.tzfile or datetime.tzinfo or str

Set the Timezone of the data.

normalizebool, default False

Normalize start/end dates to midnight before generating date range.

Deprecated since version 2.1.0.

closed{‘left’, ‘right’}, optional

Set whether to includestart andend that are on theboundary. The default includes boundary points on either end.

Deprecated since version 2.1.0.

ambiguous‘infer’, bool-ndarray, ‘NaT’, default ‘raise’

When clocks moved backward due to DST, ambiguous times may arise.For example in Central European Time (UTC+01), when going from 03:00DST to 02:00 non-DST, 02:30:00 local time occurs both at 00:30:00 UTCand at 01:30:00 UTC. In such a situation, theambiguous parameterdictates how ambiguous times should be handled.

  • ‘infer’ will attempt to infer fall dst-transition hours based onorder

  • bool-ndarray where True signifies a DST time, False signifies anon-DST time (note that this flag is only applicable for ambiguoustimes)

  • ‘NaT’ will return NaT where there are ambiguous times

  • ‘raise’ will raise an AmbiguousTimeError if there are ambiguous times.

dayfirstbool, default False

If True, parse dates indata with the day first order.

yearfirstbool, default False

If True parse dates indata with the year first order.

dtypenumpy.dtype or DatetimeTZDtype or str, default None

Note that the only NumPy dtype allowed isdatetime64[ns].

copybool, default False

Make a copy of input ndarray.

namelabel, default None

Name to be stored in the index.

Attributes

year

The year of the datetime.

month

The month as January=1, December=12.

day

The day of the datetime.

hour

The hours of the datetime.

minute

The minutes of the datetime.

second

The seconds of the datetime.

microsecond

The microseconds of the datetime.

nanosecond

The nanoseconds of the datetime.

date

Returns numpy array of pythondatetime.date objects.

time

Returns numpy array ofdatetime.time objects.

timetz

Returns numpy array ofdatetime.time objects with timezones.

dayofyear

The ordinal day of the year.

day_of_year

The ordinal day of the year.

dayofweek

The day of the week with Monday=0, Sunday=6.

day_of_week

The day of the week with Monday=0, Sunday=6.

weekday

The day of the week with Monday=0, Sunday=6.

quarter

The quarter of the date.

tz

Return the timezone.

freqstr

Return the frequency object as a string if it's set, otherwise None.

is_month_start

Indicates whether the date is the first day of the month.

is_month_end

Indicates whether the date is the last day of the month.

is_quarter_start

Indicator for whether the date is the first day of a quarter.

is_quarter_end

Indicator for whether the date is the last day of a quarter.

is_year_start

Indicate whether the date is the first day of a year.

is_year_end

Indicate whether the date is the last day of the year.

is_leap_year

Boolean indicator if the date belongs to a leap year.

inferred_freq

Tries to return a string representing a frequency generated by infer_freq.

freq

Methods

normalize(*args, **kwargs)

Convert times to midnight.

strftime(date_format)

Convert to Index using specified date_format.

snap([freq])

Snap time stamps to nearest occurring frequency.

tz_convert(tz)

Convert tz-aware Datetime Array/Index from one time zone to another.

tz_localize(tz[, ambiguous, nonexistent])

Localize tz-naive Datetime Array/Index to tz-aware Datetime Array/Index.

round(*args, **kwargs)

Perform round operation on the data to the specifiedfreq.

floor(*args, **kwargs)

Perform floor operation on the data to the specifiedfreq.

ceil(*args, **kwargs)

Perform ceil operation on the data to the specifiedfreq.

to_period(*args, **kwargs)

Cast to PeriodArray/PeriodIndex at a particular frequency.

to_pydatetime(*args, **kwargs)

Return an ndarray ofdatetime.datetime objects.

to_series([index, name])

Create a Series with both index and values equal to the index keys.

to_frame([index, name])

Create a DataFrame with a column containing the Index.

month_name(*args, **kwargs)

Return the month names with specified locale.

day_name(*args, **kwargs)

Return the day names with specified locale.

mean(*[, skipna, axis])

Return the mean value of the Array.

std(*args, **kwargs)

Return sample standard deviation over requested axis.

See also

Index

The base pandas Index type.

TimedeltaIndex

Index of timedelta64 data.

PeriodIndex

Index of Period data.

to_datetime

Convert argument to datetime.

date_range

Create a fixed-frequency DatetimeIndex.

Notes

To learn more about the frequency strings, please seethis link.

Examples

>>>idx=pd.DatetimeIndex(["1/1/2020 10:00:00+00:00","2/1/2020 11:00:00+00:00"])>>>idxDatetimeIndex(['2020-01-01 10:00:00+00:00', '2020-02-01 11:00:00+00:00'],dtype='datetime64[ns, UTC]', freq=None)

[8]ページ先頭

©2009-2025 Movatter.jp