Format built-in types for pretty printing in Deedle

154 views Asked by At

I understand that in order to pretty print things like discriminated unions in Deedle, you have to override ToString(). But what about built in types, like float?

Specifically, I want floats in one column to be displayed as percentages, or at the very least, to not have a million digits past the decimal.

Is there a way to do this?

1

There are 1 answers

0
Tomas Petricek On BEST ANSWER

There is no built-in support for doing this - it sounds like a useful addition, so if you want to contribute this to Deedle, please open an issue to discuss this! We'd be happy to accepta pull request that adds this feature.

As a workaround, I think your best chance is to transform the data in the 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 float values of a column named A are transformed using the formatting function sprintf "%f%%" (v*100.0) and the rest is left unchanged.