Formatting built-in types for printing in Deedle

I understand that in order to beautifully print things like discriminatory unions in Deedle, you have to redefine ToString(). But what about built-in types, for example float?

In particular, I want floats in one column to be displayed as percentages, or at least not to have a million digits after the decimal number.

Is there any way to do this?

+4
source share
1 answer

There is no built-in support for this - this seems like a useful addition, so if you want to contribute to Deedle, open a question to discuss this ! We will be happy to accept a transfer request that will add this feature.

As a workaround, I think your best chance is to convert the data to a frame before printing. Something like this should do the trick:

let df = frame [ "A" => series [ 1 => 0.001 ] ]

df |> Frame.map (fun r c (v:float) -> 
  if c = "A" then box (sprintf "%f%%" (v*100.0)) else box v)

This creates a new frame where all the values ​​of the floatcolumn with the name are Aconverted using the format function sprintf "%f%%" (v*100.0), and the rest remains unchanged.

+3
source

Source: https://habr.com/ru/post/1664126/


All Articles