Skip to main content

__ Back to top

__ ` Ctrl ` \+ ` K `

[ ![pandas 2.2.1 documentation - Home](../_static/pandas.svg) ](../index.html)

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

Site Navigation

  * [ Getting started ](../getting_started/index.html)
  * [ User Guide ](index.html)
  * [ API reference ](../reference/index.html)
  * [ Development ](../development/index.html)
  * [ Release notes ](../whatsnew/index.html)

  * [ __ GitHub  ](https://github.com/pandas-dev/pandas "GitHub")
  * [ __ Twitter  ](https://twitter.com/pandas_dev "Twitter")
  * [ __ Mastodon  ](https://fosstodon.org/@pandas_dev "Mastodon")

  * [ 10 minutes to pandas ](10min.html)
  * [ Intro to data structures ](dsintro.html)
  * [ Essential basic functionality ](basics.html)
  * [ IO tools (text, CSV, HDF5, â¦) ](io.html)
  * [ PyArrow Functionality ](pyarrow.html)
  * [ Indexing and selecting data ](indexing.html)
  * [ MultiIndex / advanced indexing ](advanced.html)
  * [ Copy-on-Write (CoW) ](copy_on_write.html)
  * [ Merge, join, concatenate and compare ](merging.html)
  * [ Reshaping and pivot tables ](reshaping.html)
  * [ Working with text data ](text.html)
  * [ Working with missing data ](missing_data.html)
  * [ Duplicate Labels ](duplicates.html)
  * [ Categorical data ](categorical.html)
  * [ Nullable integer data type ](integer_na.html)
  * [ Nullable Boolean data type ](boolean.html)
  * [ Chart visualization ](visualization.html)
  * [ Table Visualization ](style.html)
  * [ Group by: split-apply-combine ](groupby.html)
  * [ Windowing operations ](window.html)
  * [ Time series / date functionality ](timeseries.html)
  * Time deltas 
  * [ Options and settings ](options.html)
  * [ Enhancing performance ](enhancingperf.html)
  * [ Scaling to large datasets ](scale.html)
  * [ Sparse data structures ](sparse.html)
  * [ Frequently Asked Questions (FAQ) ](gotchas.html)
  * [ Cookbook ](cookbook.html)

  * [ __ ](../index.html)
  * [ User Guide ](index.html)
  * Time deltas 

#  Time deltas  #

Timedeltas are differences in times, expressed in difference units, e.g. days,
hours, minutes, seconds. They can be both positive and negative.

` Timedelta  ` is a subclass of ` datetime.timedelta  ` , and behaves in a
similar manner, but allows compatibility with ` np.timedelta64  ` types as
well as a host of custom representation, parsing, and attributes.

##  Parsing  #

You can construct a ` Timedelta  ` scalar through various arguments, including
[ ISO 8601 Duration ](https://en.wikipedia.org/wiki/ISO_8601#Durations)
strings.

    
    
    In [1]: import datetime
    
    # strings
    In [2]: pd.Timedelta("1 days")
    Out[2]: Timedelta('1 days 00:00:00')
    
    In [3]: pd.Timedelta("1 days 00:00:00")
    Out[3]: Timedelta('1 days 00:00:00')
    
    In [4]: pd.Timedelta("1 days 2 hours")
    Out[4]: Timedelta('1 days 02:00:00')
    
    In [5]: pd.Timedelta("-1 days 2 min 3us")
    Out[5]: Timedelta('-2 days +23:57:59.999997')
    
    # like datetime.timedelta
    # note: these MUST be specified as keyword arguments
    In [6]: pd.Timedelta(days=1, seconds=1)
    Out[6]: Timedelta('1 days 00:00:01')
    
    # integers with a unit
    In [7]: pd.Timedelta(1, unit="d")
    Out[7]: Timedelta('1 days 00:00:00')
    
    # from a datetime.timedelta/np.timedelta64
    In [8]: pd.Timedelta(datetime.timedelta(days=1, seconds=1))
    Out[8]: Timedelta('1 days 00:00:01')
    
    In [9]: pd.Timedelta(np.timedelta64(1, "ms"))
    Out[9]: Timedelta('0 days 00:00:00.001000')
    
    # negative Timedeltas have this string repr
    # to be more consistent w