How to print numpy 2D array as table with headers in Python

2 Answers

0 votes
import numpy as np 
from tabulate import tabulate

data = np.array([[12, 7, 149], [32, 100, 2]])
headers = ["Header A", "Header B", "Header C"]

table = tabulate(data, headers, tablefmt="github")

print(table)


 
   
'''
run:
   
|   Header A |   Header B |   Header C |
|------------|------------|------------|
|         12 |          7 |        149 |
|         32 |        100 |          2 |
          
'''

 



answered May 19, 2020 by avibootz
0 votes
import numpy as np 
from tabulate import tabulate
 
data = np.array([[12, 7, 149], [32, 100, 2]])
headers = ["Header A", "Header B", "Header C"]
 
table = tabulate(data, headers)
 
print(table)
 
 
  
    
'''
run:
    
  Header A    Header B    Header C
----------  ----------  ----------
        12           7         149
        32         100           2
           
'''

 



answered May 19, 2020 by avibootz
...