Add_row to data table

Absolutely to this part of the question.

You can do:

my_dict={'my_column_1': 'my_value_1', 'my_column_2': 'my_value_2'}
app_tables.my_table.add_row(**my_dict)

This is assuming you have those columns in your data table (or you have “auto-create missing columns when adding rows checked”).

If you have a single dictionary with lists as values, perhaps you could convert to a list of dictionaries and then add rows using the code above in a loop.

For example, if you have Pandas:

import pandas as pd

df=pd.DataFrame(my_dict)
list_of_dicts=df.to_dict('records') # converting to list of dicts

for d in list_of_dicts:
    app_tables.my_table.add_row(**d)

A non-Pandas way to get to a list of dicts could be:

list_of_dicts = [dict(zip(my_dict,v)) for v in zip(*my_dict.values())]

Perhaps others know a better way of adding rows to a DataTable given your initial data structure, but this is how I’ve done it in the past.

7 Likes