otterdog2000
otterdog2000

Reputation: 363

Python Dash formatting with unknown column names

If I have a Dash table structure like below where it's creating column names from the dataframe columns names. how do I add formatting to these columns? All the examples I see have fixed column names.

dash_table.DataTable(
    id='table',
    columns=[{"name": i, "id": i} for i in df2.columns],
    data=df2.to_dict('records'),
    style_data_conditional=style_data_conditional,
    )

I'm struggling on how to add column formatting to the columns definition above.

Upvotes: 0

Views: 1027

Answers (1)

coralvanda
coralvanda

Reputation: 6596

You can set the formats like this:

columns = [
    dict(id=i, name=i, type='numeric', format=FormatTemplate.percentage(2))
    for i in df2.columns
]

Taken from this page

Upvotes: 1

Related Questions