python


String formatting of timedeltas in Pandas


I noticed that Pandas knows how to smartly format a timedelta object into a string.
In [1]: df[column][rows].max()
Out[1]:
0 2 days, 02:08:07
dtype: timedelta64[ns]
When I try to do this manually I keep getting the string in nanoseconds.
In [2]: df[column][rows].max()[0]
Out[2]: numpy.timedelta64(180487000000000,'ns')
In [2]: str(df[column][rows].max()[0])
Out[2]: '180487000000000 nanoseconds'
I would rather not reinvent the wheel, so is there any way to access the string formatting method (or the string itself) that Pandas uses to show a timedelta object in x days, hh:mm:ss ?
The function is located here:
pd.tslib.repr_timedelta64
In action:
In [11]: pd.tslib.repr_timedelta64(np.timedelta64(180487000000000,'ns'))
Out[11]: '2 days, 02:08:07'

Related Links

SettingWithCopyWarning warning in python
Python tKinter EventLoop pauses calls to after() - MAC OSX
Python; NameError: name 'handsum' is not defined
nvprof is using all available GPU's when profiling python script
Get stdout from Popen when line is not being terminated
how to specify the version of python in command line for pip install
Can't see error in code
Can't run a SSH command with Paramiko/Python
Passing text file input to shell script for Syntaxnet
Can't get attribute 'function_inner' on <module '__mp_main__' from 'E:\\python\\Test\\test.py'>
Python Pandas Get Unique Count of Column
Printing results to text file
comparing and finding error between two arrays of different sizes using numpy
Django filter sort by number of ForeignKey related objects
Pipe the ouput of a hive query run on a remote machine to the local machine using python
Error message installing “Gnuplot-py” with “python setup.py install” command in Mac OS Sierra

Categories

HOME
crystal-reports
mql4
erlang
webrtc
bing
ocaml
ubuntu-16.04
docker-swarm
h2
branch.io
codeblocks
ng-admin
contact-form-7
openwrt
deeplearning4j
iso
public-key-encryption
automata
mule-studio
scenebuilder
apache-karaf
session-timeout
ms-access-2007
chocolatey
plupload
aws-cognito
cvs2svn
flexboxgrid
sql-update
nmake
servicemix
spring-ws
java-ee-7
geopandas
image-quality
vertex-buffer
ifstream
geo
pycparser
modulo
rhino
phpspreadsheet
pace
color-scheme
bing-maps-api
android-download-manager
polyfills
android-preferences
intellilock
microdata
crop
mod-fcgid
scalafx
nstouchbar
livescribe
goquery
nuget-server
unity3d-editor
polar-coordinates
emgu
gulp-typescript
svn-merge
atlassian-crowd
push-diffusion
pydio
spinlock
asymptote
datainputstream
registrykey
base32
playscape
ember-cli-addons
stackframe
symfony-2.6
candidate-key
snmp4j
suffix-array
genetic-programming
smartystreets
planetary.js
crystal-reports-10
wic
surveyor-gem
qss
process-monitor
arbor.js
gdataxml
attachevent
crocodoc
mpmovieplayer
qtembedded
ihttphandler
ets
integer-promotion
nt4
castle-validators

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App