问题
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

回答1:
given a dummy 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
来源:https://stackoverflow.com/questions/64063517/time-difference-between-timestamps-in-a-pandas-dataframe-as-histogram