I am trying to create a table of performance metrics using PrettyTable. Given the table layout, it would be best to fill the table by column using a list of metrics and a list of values with the add_column
option. However, when I try to do that, the output gives all the lists values in a single row:
from prettytable import PrettyTable
mse=123
mae=456
r2=789
performance_metrics=['Mean Squared Error', 'Mean Absolute Error', 'R-Squared']
values=[mse, mae, r2]
#CREATE TABLE
table = PrettyTable()
table.title = 'Model Performance'
column_names=['Metric', 'Value']
table.add_column(column_names[0],[performance_metrics])
table.add_column(column_names[1],[values])
print(table)
+------------------------------------------------------------------------------+
| Model Performance |
+------------------------------------------------------------+-----------------+
| Metric | Value |
+------------------------------------------------------------+-----------------+
| ['Mean Squared Error', 'Mean Absolute Error', 'R-Squared'] | [123, 456, 789] |
+------------------------------------------------------------+-----------------+
How can I fix this possibly without resorting to adding each row on its own?
UPDATE: Reading back the question I realized I forgot to attach the desired output, which is obviously something like the following:
+------------------------------------------------------------------------------+
| Model Performance |
+------------------------------------------------------------+-----------------+
| Metric | Value |
+------------------------------------------------------------+-----------------+
| Mean Squared Error | 123 |
+------------------------------------------------------------+-----------------+
| Mean Absolute Error | 456 |
+------------------------------------------------------------+-----------------+
| R-Squared | 789 |
+------------------------------------------------------------+-----------------+