-1

Basically 4 elements are there in order, i need to paste in group of 4

My input

hr avg(total) avg(rate1) avg(rate2)
0   
36.27   
0.37    
35.9
1   
73.26   
11.7    
61.56

Expected out

hr avg(total) avg(rate1) avg(rate2)
0   36.27   0.37    35.9
1   73.26   11.7    61.56
  • 1
    Use this link, it shows you how to nicely split arrays and data: https://stackoverflow.com/questions/12575421/convert-a-1d-array-to-a-2d-array-in-numpy – Norbert Wesolowski Jan 06 '20 at 11:55

2 Answers2

1

If you want solution without pandas, you can use this example (txt is variable containing text from your question):

from io import StringIO
from itertools import groupby

reader = StringIO(txt)

# read headers
vals = [next(reader).split()]
# read the rest
for _, g in groupby(enumerate(reader), lambda k: k[0] // len(vals[0])):
    vals.append([val.strip() for _, val in g])

for line in vals:
    print(*line, sep='\t')

Prints:

hr  avg(total)  avg(rate1)  avg(rate2)
0   36.27   0.37    35.9
1   73.26   11.7    61.56
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91
0

code:

print("hr","avg(total)","avg(rate1)","avg(rate2)")
print("{}\t{}\t{}\t{}".format(0,36.27,0.37,35.9))
print("{}\t{}\t{}\t{}".format(1,73.26,11.7,61.56))

output:

hr avg(total) avg(rate1) avg(rate2)
0   36.27   0.37    35.9
1   73.26   11.7    61.56
CC7052
  • 563
  • 5
  • 16