How to change the column width of a DataFrame

I have the following data frame:

julia> df
11729×4 DataFrame
   Row │ time_rel  X                                  Y                                  Z                                 
       │ Float64   Array…                             Array…                             Array…                            
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     1 │     0.05  [6.29952e-22, 12.5146, 25.0163, …  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [-3.30573e-18, 21.6467, 43.301, …
     2 │     0.1   [8.98951e-20, 12.577, 25.0894, 3…  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [1.68433e-19, 21.6462, 43.33, 65…
     3 │     0.15  [-3.72055e-20, 12.695, 25.2191, …  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [-6.84735e-19, 21.6405, 43.3805,…
     4 │     0.2   [-4.87891e-18, 12.8217, 25.3771,…  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [-4.55766e-18, 21.6244, 43.4044,…
     5 │     0.25  [9.19222e-19, 12.8774, 25.5466, …  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [2.33055e-18, 21.6284, 43.3792, …
     6 │     0.3   [-3.94529e-22, 12.8533, 25.6785,…  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [1.26796e-19, 21.6576, 43.3318, …
     7 │     0.35  [-4.98143e-19, 12.8388, 25.7189,…  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [1.44401e-18, 21.6672, 43.3098, …
     8 │     0.4   [1.84899e-19, 12.8775, 25.7024, …  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0…  [-6.30753e-20, 21.6395, 43.3102,…
   ⋮   │    ⋮                      ⋮                                  ⋮                                  ⋮
 11722 │   586.1   [1.20869e-19, 82.8057, 165.425, …  [4.63993e-20, -16.9691, -33.9596…  [3.35357e-20, 39.6229, 79.6217, …
 11723 │   586.15  [4.28343e-19, 82.8001, 165.412, …  [-7.72324e-21, -17.0673, -34.149…  [-7.82128e-21, 39.7085, 79.7984,…
 11724 │   586.2   [2.15631e-20, 82.7932, 165.397, …  [2.62671e-20, -17.1603, -34.3303…  [-5.07658e-20, 39.7979, 79.9815,…
 11725 │   586.25  [-2.60913e-19, 82.7852, 165.38, …  [-1.83576e-20, -17.2479, -34.501…  [2.56848e-20, 39.8915, 80.171, 1…
 11726 │   586.3   [2.44041e-19, 82.7762, 165.362, …  [-1.30759e-20, -17.3299, -34.664…  [1.25852e-20, 39.9892, 80.3667, …
 11727 │   586.35  [-2.32302e-19, 82.7662, 165.342,…  [-2.92211e-20, -17.4062, -34.816…  [-4.5892e-21, 40.0906, 80.5682, …
 11728 │   586.4   [-1.30687e-19, 82.7554, 165.321,…  [-1.30402e-20, -17.4772, -34.96,…  [1.49444e-20, 40.1954, 80.7753, …
 11729 │   586.45  [-2.99227e-20, 82.744, 165.299, …  [-1.46538e-20, -17.5431, -35.093…  [7.80318e-20, 40.3031, 80.9879, …
                                                                                                         11713 rows omitted

I would like to see all elements in the columns X, Y and Z. My screen is wide enough.

I already tried:

ENV["COLUMNS"]=1000

But it had no effect.

Any idea?

3 Likes

It is in the manual introduction:

Printing options can be adjusted by calling the show function manually: show(df, allrows=true) prints all rows even if they do not fit on screen and show(df, allcols=true) does the same for columns.

2 Likes

Well, this does not help. All columns are shown, but not the full content of the colums X, Y and Z. The column width is too small, and I would like to know how I can adjust it.

2 Likes

I recommend to check https://github.com/ronisbr/TerminalPager.jl if you want to see all rows in the REPL, see [ANN] TerminalPager v0.1.0.

Sorry, just now I noticed that you actually have a column of arrays. I am not entirely sure if there is something already done for such a niche use case. The problem here is probably that the Dataframe calls show and show default behaviour for Arrays is the one that you are seeing. You either would need to change this behaviour globally, or change the type of the columns to something that is not compacted by show.

It might not be possible. DataFrames doesn’t use show for printing an array within a dataframe, it writes its own method so it has defaults that are more conducive to interactive work.

Best bet is to just stuck with PrettyTables directly when you need to show your data frame. Not sure if it will work there either, I guess, though.

Hi!

Just pass a very large number to truncate argument of show:

julia> show(df, truncate = 100)
100×3 DataFrame
 Row │ time_rel   X                                                    Y
     │ Float64    Array…                                               Array…
─────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1 │ 0.156148   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   2 │ 0.670685   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   3 │ 0.218317   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   4 │ 0.903568   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   5 │ 0.384331   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   6 │ 0.87034    [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   7 │ 0.480099   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   8 │ 0.434823   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
   9 │ 0.408432   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  10 │ 0.0756601  [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  11 │ 0.716183   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  12 │ 0.76725    [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  13 │ 0.183719   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  14 │ 0.653708   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  15 │ 0.145333   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  16 │ 0.340446   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  17 │ 0.0866462  [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  18 │ 0.284077   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  19 │ 0.777791   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  20 │ 0.648991   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  21 │ 0.72242    [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  22 │ 0.169519   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  23 │ 0.326246   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  24 │ 0.210356   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  25 │ 0.909383   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  26 │ 0.945082   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  ⋮  │     ⋮                               ⋮                                                    ⋮
  76 │ 0.256647   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  77 │ 0.101922   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  78 │ 0.0582223  [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  79 │ 0.70046    [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  80 │ 0.794336   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  81 │ 0.750497   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  82 │ 0.108739   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  83 │ 0.603001   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  84 │ 0.0611404  [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  85 │ 0.577953   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  86 │ 0.655606   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  87 │ 0.491304   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  88 │ 0.819947   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  89 │ 0.194484   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  90 │ 0.469323   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  91 │ 0.969326   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  92 │ 0.96581    [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  93 │ 0.901603   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  94 │ 0.944663   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  95 │ 0.878888   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  96 │ 0.727362   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  97 │ 0.0358795  [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  98 │ 0.522901   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
  99 │ 0.283858   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
 100 │ 0.904986   [0.307362, 0.334855, 0.934461, 0.885757, 0.0761271]  [0.492038, 0.630796, 0.00360602, 0.902196, 0.743641]
                                                                                                             49 rows omitted

EDIT: You can also use the parameter maximum_columns_width of pretty_table: show(df, maximum_columns_width = 0)

6 Likes

Thanks a lot, that did the trick!

1 Like

Yes, TerminalPager is very nice, but the parameter truncate=100 is still needed.

1 Like