【发布时间】:2020-09-26 01:38:50
【问题描述】:
我有一个数据框,其中一列是所有时间戳,如下所示。我现在需要做的是计算每个时间戳之间的差异,然后使用这些差异绘制为直方图。 我无法破译如何计算差异。任何帮助将不胜感激。
0 2020-09-16 00:00:02.713264
1 2020-09-16 00:00:02.827854
2 2020-09-16 00:00:05.919288
3 2020-09-16 00:00:05.940775
4 2020-09-16 00:00:06.682184
【问题讨论】:
-
您应该能够将差异以秒为单位绘制为直方图,例如
df['timestamp'].diff().dropna().dt.total_seconds().plot.hist() -
谢谢。上半场效果很好。但我在情节上遇到错误 - UFuncTypeError: Cannot cast ufunc 'less' input 1 from dtype('float64') to dtype('
-
在我原来的评论中添加了
.dropna();现在应该可以工作了。 -
thanks.the dropna 可以移除 NaT 但它不会绘图。我得到了这个: UFuncTypeError: Cannot cast ufunc 'less' input 1 from dtype('float64') to dtype('
标签: python pandas dataframe datetime