在 Python 中一起打印多个表格

Printing multiple tables together in Python

我有这个代码:

import numpy as np

headings = np.array(["userID","name","bookingID"])
data = np.array([[1111111,"Joe Bloggs",2222222][1212121,"Jane Doe",3333333]])

如何以这种方式打印此数据:

userID
1111111
name
Joe Bloggs
bookingID
2222222
userID
1212121
name
Jane Doe
bookingID
3333333

这是我最接近的...

keys = headings.values
datas = df.values
for i in datas:
    for j in keys:
        print(j)
        print(i)

结果:

userID
[1111111 'Joe Bloggs' 2222222]
name
[1111111 'Joe Bloggs' 2222222]
bookingID
[1111111 'Joe Bloggs' 2222222]
userID
[1212121 'Jane Doe' 3333333]
name
[1212121 'Jane Doe' 3333333]
bookingID
[1212121 'Jane Doe' 3333333]

但是我正在努力执行额外的步骤以将其缩小到每个键的特定数据...有人可以帮忙吗? (还有人可以推荐一个更好的问题标题吗?)

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