siuba icon indicating copy to clipboard operation
siuba copied to clipboard

Support glimpse function

Open chriscardillo opened this issue 2 years ago • 3 comments

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.

chriscardillo avatar Mar 29 '22 21:03 chriscardillo

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
  )
)
image

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
image

(Note how this also jacks up representations)

Handles nested representations via a summary

image

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]>]"

machow avatar Mar 29 '22 22:03 machow

This is cool. Also want to implement it with datar.

pwwang avatar Apr 08 '22 15:04 pwwang

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!

Holer90 avatar Feb 27 '23 10:02 Holer90