For example:
header = ['a','b','c']
data = ['1','2','3','4','5','6',...,'100']
How can I combine each three of the data to match the header?
Expected output:
CodePudding user response:
Here's how you can do this.
import csv
header = ['a','b','c']
data = ['1','2','3','4','5','6','7','8','9']
file = csv.writer(open(f"testing.csv", "a",newline=''))
file.writerow(header)
for i in range(0,len(data),3):
new_list = data[i:i 3]
file.writerow(new_list)
Here's the screenshot of 'testing.csv':