简体   繁体   English

大熊猫数据帧中时间戳之间的时间差作为直方图

[英]time difference between timestamps in a pandas dataframe as histogram

I have a data frame with one column that is all timestamps like below.我有一个数据框,其中一列都是时间戳,如下所示。 What I need to do is now calculate the difference between each of the timestamps and then use those differences to plot as a histogram.我现在需要做的是计算每个时间戳之间的差异,然后使用这些差异绘制直方图。 I am unable to decipher how to do the calculation on the differences.我无法破译如何计算差异。 Any help would be appreciated.任何帮助,将不胜感激。

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

在此处输入图片说明

given a dummy df给定一个虚拟 df

# df
#                    timestamp
# 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

you should be able to use你应该可以使用

ax = df['timestamp'].diff().dropna().dt.total_seconds().plot.hist()
ax.set_xlabel('timedelta[s]')

...which should spawn a plot like ...这应该会产生一个像在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM