-1

My dataframe has 100+ columns; so doing head() shown only a small portion of them. I'd like to see the values of all of the columns for a sampling of the rows e.g. 10 rows. Moreover I'd prefer for the values to be shown vertically (as to avoid needing to scroll horizontally through the table).

Neil
  • 7,482
  • 6
  • 50
  • 56
  • 2
    Does this answer your question? [Pretty-print an entire Pandas Series / DataFrame](https://stackoverflow.com/questions/19124601/pretty-print-an-entire-pandas-series-dataframe) – mozway Aug 05 '21 at 05:49
  • thanks @mozway this partially answers my question; however in my case; I don't need to display the whole df (I have 1M rows); but do want to display all of the columns for a sampling of rows – Neil Aug 05 '21 at 05:54
  • 1
    Well, use `df.head()` as you mentioned in your question. You can also use `df.sample(10)` if you want 10 arbitrary rows. – mozway Aug 05 '21 at 06:00

4 Answers4

1

You can set the display.max_column option to None:

pd.set_option('display.max_columns', None)

See the list of pandas options

Edit:

with pd.option_context('display.max_rows', None):
    df.sample(10).T
mozway
  • 194,879
  • 13
  • 39
  • 75
  • Thanks; this works. However, horizontal scrolling is not very convenient; if possible; I'd also would like an option to display columns vertically (in transposed format) – Neil Aug 05 '21 at 05:52
1

@Neil, If you want to display columns vertically (in transposed format), use - df.T.head()

Vinay
  • 126
  • 7
  • this doesn't quite work; `head` show only the first `5` columns (I want all) – Neil Aug 05 '21 at 06:05
  • 1
    If you want all columns then use only - df.T If rows are more than 30 , then it will some rows , So first use - pd.set_option("display.max_rows", None) then use df.T – Vinay Aug 05 '21 at 06:14
0

Try to use dtypes that will show names and types of the columns:

 df.dtypes

It is short and very informative.

Alexey
  • 386
  • 2
  • 9
0

I got the desired results by combining and tweaking answers from @mozway and @Vinay (thanks)

# note that rows/cols will be transposed
pd.set_option('display.max_column', 20) 
pd.set_option('display.max_rows', None)
df.T.head(df.shape[1])
Neil
  • 7,482
  • 6
  • 50
  • 56