Skip to content

Instantly share code, notes, and snippets.

@jmquintana79
Last active May 20, 2024 08:16
Show Gist options
  • Save jmquintana79/4d7a8cb440889dd3c3c294f36ec5539c to your computer and use it in GitHub Desktop.
Save jmquintana79/4d7a8cb440889dd3c3c294f36ec5539c to your computer and use it in GitHub Desktop.
# original column
In [15]: df["timedelta_column"]
Out[15]:
0 1 days 00:00:00
1 3 days 02:00:00
2 5 days 04:00:00
3 7 days 06:00:00
4 9 days 08:00:00
5 11 days 10:00:00
dtype: timedelta64[ns]
# all components
In [17]: df["timedelta_column"].dt.components
Out[17]:
days hours minutes seconds milliseconds microseconds nanoseconds
0 1 0 0 0 0 0 0
1 3 2 0 0 0 0 0
2 5 4 0 0 0 0 0
3 7 6 0 0 0 0 0
4 9 8 0 0 0 0 0
5 11 10 0 0 0 0 0
# only days (integer)
In [16]: s.dt.days
Out[16]:
0 1
1 3
2 5
3 7
4 9
5 11
dtype: int64
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment