siuba
siuba copied to clipboard
Support glimpse function
Would be great to have dplyr's glimpse function implemented in siuba and loaded in with from siuba import *
.
glimpse
is really useful because pandas dataframes don't always print nicely.
Agreed it would be nice! As I understand, glimpse (which is implemented in the pillar package) basically does the following:
- transposes the normal table view, so each column shows up as a row
- prints shape up top (e.g. Rows: 10, Columns: 2)
- for each column, chooses the number of elements to show based on terminal width
- e.g. one column might show 3, while another shows 15 (shorter representations)
- has a generic
format_glimpse
for handling things like lists
Examples
Choosing n elements to show per column
glimpse(
data.frame(
x = c(paste0(rep("abc", 10), collapse = ""), rep("zzz", 9)),
y = 1:10
)
)

Different from straight transposing
Transposing a dataframe doesn't dynamically select number of columns (and jacks up the object representations; e.g. ints go to floats, etc..):
from siuba.data import mtcars
mtcars.head().T

(Note how this also jacks up representations)
Handles nested representations via a summary

To see how it handles each column:
nested = mtcars %>% nest(data = c(-cyl))
pillar:::format_glimpse_1(nested$data)
# [1] "[<tbl_df[7 x 10]>], [<tbl_df[11 x 10]>], [<tbl_df[14 x 10]>]"
This is cool. Also want to implement it with datar.
I have implemented the glimpse function in pandas
, opened a feature request and is in the process of submitting a pull request. Now we just need to hope someone has the time to review the pull request!