Pandas中timedeltas的字符串格式 [英] String formatting of timedeltas in Pandas
本文介绍了Pandas中timedeltas的字符串格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我注意到Pandas知道如何将timedelta
对象格式化为字符串.
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'
我不想重蹈覆辙,所以有什么方法可以访问熊猫用来在x days, hh:mm:ss
中显示timedelta
对象的字符串格式化方法(或字符串本身)?
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
?
推荐答案
该函数位于此处:
pd.tslib.repr_timedelta64
实际情况:
In [11]: pd.tslib.repr_timedelta64(np.timedelta64(180487000000000,'ns'))
Out[11]: '2 days, 02:08:07'
这篇关于Pandas中timedeltas的字符串格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文