PrettyTables; DataFrames: Combination

If you do this

#df is some DataFrame
#pipe the first 10 rows to be formatted with PrettyTables
first(df, 10) |> pretty_table

you get the expected outcome.

But I seek (e.g.) this:

#pick first 10 rows, print with PrettyTables without borders (and so on)
first(df, 10) |> pretty_table(tf = borderless)

Is there some syntax recommended?

julia> map(x->round(x,digits=2),rand(4,2)) 
4Γ—2 Array{Float64,2}:
 0.27  0.37
 0.42  0.37
 0.35  0.15
 0.38  1.0 

julia> map(x->round(x,digits=2),rand(4,2)) |> pretty_table
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Col. 1 β”‚ Col. 2 β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚    0.9 β”‚    0.6 β”‚
β”‚   0.85 β”‚   0.09 β”‚
β”‚   0.09 β”‚   0.61 β”‚
β”‚   0.77 β”‚   0.14 β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”˜

julia> map(x->round(x,digits=2),rand(4,2)) |> x->pretty_table(x,tf = borderless)

  Col. 1   Col. 2  
                   
    0.18     0.71  
    0.84     0.72  
    0.95      0.0  
    0.35     0.89  

2 Likes

There seems to be some confusion about julia’s |> vs R’s %>%.

R’s %>% transforms things so that x %>% f(y) is equivalent to f(x, y). Julia’s |> operator doesn’t work like that, one reason that choice was made is because Julia doesn’t place the same emphasis on the first argument of functions the way the tidyverse ecosystem does.

the poster above gives a good example, you could also use Pipe.jl or a similar package.

using Pipe
julia> @pipe first(df, 10) |> pretty_table(_, tf = borderless)

Alright. Thanks, both.