我有一个数据文件输出,比如
0 0.010168 7191516 branch-instructions
1 0.010168 33047525 instructions
2 0.010168 290566 cache-references
3 0.010168 104974 cache-misses
4 0.010168 25109349 cpu-cycles
... ... ... ...
1913 3.376448 2524814 instructions
1914 3.376448 32524 cache-references
1915 3.376448 18957 cache-misses
1916 3.376448 2144874 cpu-cycles
1917 3.376448 3349 branch-misses我需要将它写到csv中,第三列作为标题,与其对应的值如下
time branch-instructions instructions cache-references cache-misses cpu-cycles branch-misses
0.010168 7191516 33047525 290566 104974 25109349 2458 我该怎么做?任何帮助都是非常感谢的。
发布于 2022-03-11 20:24:16
您需要在第二列上循环,写出时间,然后只写值,直到到达不同的时间为止。您可能希望同时控制第四列中的文本是正确的。
因此,步骤如下:
h 19再次迭代H 210F 211中创建一条新行。
与…有关的东西:
#Prepare reepting data
toReceive = ["time", "branch-instructions", "instructions"]#....
#Split by line your file
lines = data_imported.split("\n")
sameTime = True
i=0
refTime=lines[i].split(" ")[1]
#Loop with time as criteria
while(i<len(lines)):
sameTIme=True
localReceive=refTime
while(sameTime):
#Split by elements
elements = lines[i].split(" ")
sameTime=elements[1]==refTime
localReceive.append(elements[2])
refTime=elements[1]
toReceive.append(localReceive)https://stackoverflow.com/questions/71444142
复制相似问题