whytheq whytheq - 5 months ago 52
Python Question

pandas.set_option to give detail of Dataframe rather than returning frame

I have a

DataFrame
called
result
.

In the tutorial I'm watching Wes McKinney is getting the following return data when he executes a cell with just the name of the df in it - when I execute a cell with
result
in it I get the whole frame being returned.

Is there a pandas set_option I can use to swap between return info?

enter image description here

Answer

there is a display.large_repr option for that:

In [95]: pd.set_option('large_repr', 'info')

In [96]: df
Out[96]:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000000 entries, 0 to 999999
Data columns (total 3 columns):
a    1000000 non-null int32
b    1000000 non-null int32
c    1000000 non-null int32
dtypes: int32(3)
memory usage: 11.4 MB

from docs:

display.large_repr : ‘truncate’/’info’

For DataFrames exceeding max_rows/max_cols, the repr (and HTML repr) can show a truncated table (the default from 0.13), or switch to the view from df.info() (the behaviour in earlier versions of pandas).

[default: truncate] [currently: truncate]

PS You may also want to read about frequently used pandas options

but IMO it would be much more convenient and more conscious to use .info() function:

result.info()

demo:

In [92]: df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000000 entries, 0 to 999999
Data columns (total 3 columns):
a    1000000 non-null int32
b    1000000 non-null int32
c    1000000 non-null int32
dtypes: int32(3)
memory usage: 11.4 MB

In [93]: df.head()
Out[93]:
   a  b  c
0  1  0  1
1  6  1  9
2  5  2  3
3  6  4  3
4  8  9  2
Comments