import numpy as np
headings = np.array(["userID","name","bookingID"])
data = np.array([[1111111,"Joe Bloggs",2222222],[1212121,"Jane Doe",3333333]])
for sublist in data: #iterate through data
for ind, value in enumerate(sublist): #iterate through each sublist and remember index
print(headings[ind]) #print the element in headings that corresponds to index
print(value) #print the element
输出:
>>>userID
>>>1111111
>>>name
>>>Joe Bloggs
>>>bookingID
>>>2222222
>>>userID
>>>1212121
>>>name
>>>Jane Doe
>>>bookingID
>>>3333333