2017-03-03 34 views
-1

我有两个文本文件(file1.txt和file2.txt)。如何减去Python中的时间戳和绘图?

FILE1.TXT有开始时间戳值的列表,如:

1488407827454 
1488407827485 
1488407827554 
1488407827584 
1488407827654 

FILE2.TXT有结束时间戳值的列表,如:

1488407827954 
    1488407827985 
    1488407827994 
    1488407827997 
    1488407829999 

如何从开始时间戳减去结束时间戳记从这两个文件得到实际的时间毫秒在python和剧情CDF?

回答

0

也许是这样的:

# 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() 

产地: enter image description here

+0

这就是我一直在寻找。完美 – peter

+0

酷,很高兴它帮助你(并感谢接受!)干杯:) – davedwards