我有两个文本文件(file1.txt和file2.txt)。
file1.txt 具有起始时间戳值列表,例如:
1488407827454
1488407827485
1488407827554
1488407827584
1488407827654
file2.txt 具有结束时间戳值列表,例如:
1488407827954
1488407827985
1488407827994
1488407827997
1488407829999
如何从这两个文件的开始时间戳中减去结束时间戳,以获取 Python 中以毫秒为单位的实际时间列表并绘制 CDF?
也许是这样的:
# Read and subtract the timestamps
timediff = []
with open('file1.txt', 'r') as f1:
with open('file2.txt', 'r') as f2:
f1_lines = f1.readlines()
f2_lines = f2.readlines()
f1_nums = map(int, f1_lines)
f2_nums = map(int, f2_lines)
for t1 in f1_nums:
for t2 in f2_nums:
timediff.append(t2-t1)
# plot the CDF
import numpy as np
import matplotlib.pyplot as plt
data = np.array(timediff)
# Choose how many bins you want here
num_bins = 20
# Use the histogram function to bin the data
counts, bin_edges = np.histogram(data, bins=num_bins, normed=True)
# Now find the cdf
cdf = np.cumsum(counts)
# And finally plot the cdf
plt.plot(bin_edges[1:], cdf)
plt.show()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句