Round to 2 decimals using Arquero


I am surprised this is complicated…or maybe my brain is out… Notebook here:

I understand the problem is related to this previous question here, but I can’t make it work.

1 Like

Here you go:

    count: d => op.count(),
    culmen_min: d => op.min(d.culmen_depth_mm),
    culmen_max: d => op.max(d.culmen_depth_mm),
  }).view({format: {
    culmen_min: {digits: 2},
    culmen_max: {digits: 2}

.view is an Observable-only table function that’s defined in Arquero / UW Interactive Data Lab | Observable. It passed options through to .toHTML(), which accepts both maxdigits and a more specific per-column digits option.

I did not discover these options until after I had dug through the code and knew what to look for, though.


What I actually wanted to do (sorry for being not clear) is to use Inputs.table() to show the resulting table (I like Inputs.table() more than arquero’s view()). i.e.:

Create new df:

dt_new = dt
    count: d => op.count(),
    culmen_min: d => Math.round(op.min(d.culmen_depth_mm) * 100) / 100,
    culmen_max: d => (Math.round(op.max(d.culmen_depth_mm) * 100) / 100)

And then show in table:


The table look like this:

I guess the question now is, can I format Inputs.table() so I have the 2 digits here?

Apologies for all the confusion.

You can provide format callbacks for each column to an Inputs.table(). Here I’ve also added two options to make the table fit its contents (instead of always spanning the entire width):

Inputs.table(dt_new, {
  layout: "auto",
  maxWidth: "max-content",
  format: {
    culmen_min: d => d.toFixed(2),
    culmen_max: d => d.toFixed(2),
1 Like

:raised_hands: Thank you!