How to change default precision for all float dtypes in pn.widgets.Tabulator

So in the tabulator widget, if you pass a float it will format it will the CellFormatter which will give you all decimals. As written in the documentation I can specify the formatter for each column like this:

formatters = {
    'col1': NumberFormatter(format='0.00'),
    'col2': NumberFormatter(format='0.00'),

But i would like to set the default precision to 2 decimals on all columns, how do i do that?

I have tried to play a bit around with the formatterParams and configuration parameter, but i did not seem to understand how to use it. it is not exactly clear to me how you can update the underlying tabulator params. my best attempt:
pn.widgets.Tabulator(df, configuration={"formatterParams":{"precision": 1}})

I had a look here, but i cant figure out where to find the any settings that would help me.

I don’t think there’s a way to do that for all the columns at once (please someone correct me if I’m wrong!). I’d just do something like:

import numpy as np, pandas as df
df = pd.DataFrame(...)
formatters = {c: NumberFormatter(format='0.00') for c in df.columns if df[c].dtype == np.float64}
1 Like