Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.timedelta_range#

pandas.timedelta_range(start=None,end=None,periods=None,freq=None,name=None,closed=None,*,unit=None)[source]#

Return a fixed frequency TimedeltaIndex with day as the default.

Parameters:
startstr or timedelta-like, default None

Left bound for generating timedeltas.

endstr or timedelta-like, default None

Right bound for generating timedeltas.

periodsint, default None

Number of periods to generate.

freqstr, Timedelta, datetime.timedelta, or DateOffset, default ‘D’

Frequency strings can have multiples, e.g. ‘5h’.

namestr, default None

Name of the resulting TimedeltaIndex.

closedstr, default None

Make the interval closed with respect to the given frequency tothe ‘left’, ‘right’, or both sides (None).

unitstr, default None

Specify the desired resolution of the result.

Added in version 2.0.0.

Returns:
TimedeltaIndex

Notes

Of the four parametersstart,end,periods, andfreq,exactly three must be specified. Iffreq is omitted, the resultingTimedeltaIndex will haveperiods linearly spaced elements betweenstart andend (closed on both sides).

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

Examples

>>>pd.timedelta_range(start='1 day',periods=4)TimedeltaIndex(['1 days', '2 days', '3 days', '4 days'],               dtype='timedelta64[ns]', freq='D')

Theclosed parameter specifies which endpoint is included. The defaultbehavior is to include both endpoints.

>>>pd.timedelta_range(start='1 day',periods=4,closed='right')TimedeltaIndex(['2 days', '3 days', '4 days'],               dtype='timedelta64[ns]', freq='D')

Thefreq parameter specifies the frequency of the TimedeltaIndex.Only fixed frequencies can be passed, non-fixed frequencies such as‘M’ (month end) will raise.

>>>pd.timedelta_range(start='1 day',end='2 days',freq='6h')TimedeltaIndex(['1 days 00:00:00', '1 days 06:00:00', '1 days 12:00:00',                '1 days 18:00:00', '2 days 00:00:00'],               dtype='timedelta64[ns]', freq='6h')

Specifystart,end, andperiods; the frequency is generatedautomatically (linearly spaced).

>>>pd.timedelta_range(start='1 day',end='5 days',periods=4)TimedeltaIndex(['1 days 00:00:00', '2 days 08:00:00', '3 days 16:00:00',                '5 days 00:00:00'],               dtype='timedelta64[ns]', freq=None)

Specify a unit

>>>pd.timedelta_range("1 Day",periods=3,freq="100000D",unit="s")TimedeltaIndex(['1 days', '100001 days', '200001 days'],               dtype='timedelta64[s]', freq='100000D')

[8]ページ先頭

©2009-2025 Movatter.jp