import pandas as pd
# 读取数据,假设数据存储在名为 'data.txt' 的文件中,且列之间以制表符分隔
data = pd.read_csv('t.txt', sep='\s+', header=None)
# 初始化总和为0
total_sum = 0
total_sum_first = 0
tag_line = 11 #query名称所在列
length_line = 6 #query比对上的长度所在列
# 遍历数据,计算满足条件的总和
for index, row in data.iterrows():
print(index)
if index == 0:
total_sum_first = data.iloc[index, length_line]
data.at[index, 'total_sum'] = total_sum_first
elif 0 < index < len(data) - 1 and row[tag_line] == data.iloc[index - 1, tag_line]:
total_sum = data.iloc[index - 1, length_line] + total_sum + data.iloc[index, length_line]# 累加第七列内容
data.at[index, 'total_sum'] = total_sum
elif 0 < index < len(data) - 1 and not row[tag_line] == data.iloc[index - 1, tag_line]:
print("{}的对比长度是{}".format(data.iloc[index - 1, 11], data.iloc[index - 1, 15]))
print(data.iloc[index - 1, 15]/data.iloc[index - 1, 14])
data.at[index, 'total_sum'] = data.iloc[index, 6]
total_sum = 0
elif index == len(data) - 1:
total_sum = data.iloc[index - 1, length_line] + total_sum + data.iloc[index, length_line]
data.at[index, 'total_sum'] = total_sum
print("{}的对比长度是{}".format(data.iloc[index, 11], data.iloc[index, 15]))
print(data.iloc[index, 15] / data.iloc[index, 14])
print(data) #仅作最终测试使用!
coverage.py (true!)
最新推荐文章于 2024-09-03 17:22:28 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)