我有类似的数据帧的输出
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
我该怎么做?感谢提供的任何帮助
您需要在第二列上循环,写入时间,然后只写入值,直到到达不同的时间。您可能希望同时控制第四列中的文本是否正确。
所以步骤是:
- 绕线
- 在每一行检查第一次的时间
- 在新csv中写入值
- 如果时间不同,请更改您的第一次时间并在新csv中创建新行
- 再次迭代
类似的东西
#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)