-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Add .dt.total_seconds() method for timedelta64 Series #10817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
canoncially this is just an astype or division operation
I suppose could add a |
+1 on a |
ENH: Add Series.dt.total_seconds GH #10817
Wonderful! Thank you — Pandas is an unusually responsive project to feature suggestions, and gets better with each version. |
And thank you, @jreback, for the idea of a |
@brandon-rhodes np. issues building up like crazy, so trying to work them down :) |
Background: I am trying to build a horizonal bar graph that shows me when various builds on a server started and ended, so that I can see visually which builds overlapped in time. But the idea that a horizontal bar graph's bar-width would be a timedelta seems completely foreign to all of the plotting libraries that I have tried today (matplotlib, bokeh, ggplot), so I want to punt and instead reduce my timedelta64's to a floating-point number of days. I can then fudge the axes to display dates anyway.
Problem: there is no easy way to move from a timedelta64 to the standard Python idea of an ordinal date. I would have to extract all of the components manually (days, seconds, fractions of a second) and then multiply them each by an appropriate factor and then add them back together.
The Python
timedelta
class has an alternative that I like very much: atotal_seconds()
method that expresses then entire value of thetimedelta
as a single scalar number of seconds.This is not a perfect solution, since the factors it uses internally neglect the fact that a day might have included a leap second, but it works pretty well for non-astronomical use.
Could a
Series.dt.total_seconds()
method be added that returns the floating point valuedays * 86400 + seconds + microseconds / 1e6
? It would be a great convenience for moving from date-land to scalar-land before plotting. Thanks!The text was updated successfully, but these errors were encountered: