【发布时间】:2019-09-22 07:23:35
【问题描述】:
我试图获取 csv 文件中值出现之间的平均、最大和最小时间差。 包含多个列和行。 我目前正在使用 python 并尝试使用 pandas 来解决我的问题。
我已设法将 csv 文件分解为我想要从中获取时差的列和时间列。
“有效负载”列“值出现”发生的位置。
看起来像:
时间 |有效载荷 12.1 2368 13.8 2508
我还尝试在值发生时获取数组中的时间,并尝试单步执行数组但失败了。我觉得有一种更简单的方法可以做到这一点。
def average_time(avg_file):
avg_read = pd.read_csv(avg_file, skiprows=2, names=new_col_names, usecols=[2, 3], na_filter=False, skip_blank_lines=True)
test=[]
i=0
for row in avg_read.payload:
if row != None:
test[i]=avg_read.time
i+=1
if len[test] > 2:
average=test[1]-test[0]
i=0
test=[]
return average
csv 文件目前的样子:
time | payload
12.1 2250
12.5 2305
12.9 (blank)
13.1 (blank)
13.5 2309
14.6 2350
14.9 2680
15.0 (blank)
我想获得有效载荷列中的值之间的时间差异。
之间的示例时间2250 and 2305 --> 12.5-12.1 = 0.4 sec
和get之间的区别
2305 and 2309 --> 13.5-12.5 = 1 s
跳过空白数字 稍后获得最大、最小和平均差异。
【问题讨论】:
标签: python pandas csv parsing time