whytheq
whytheq

Reputation: 35577

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

Upvotes: 1

Views: 472

Answers (2)

MaxU - stand with Ukraine
MaxU - stand with Ukraine

Reputation: 210892

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

Upvotes: 1

Yarnspinner
Yarnspinner

Reputation: 882

df.info(verbose=None, buf=None, max_cols=None, memory_usage=None, null_counts=None) method will give you what you want. By default, information about the number of values and the size of the dataframe will be displayed. The documentation is here. The verbose setting might be particularly useful for larger datasets as it shows full output including number of notnull values.

Default:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 100 entries, 0 to 99
Columns: 10 entries, 0 to 9
dtypes: float64(10)
memory usage: 7.9 KB

With verbose = True:

<class 'pandas.core.frame.DataFrame'>
RangeIndex: 100 entries, 0 to 99
Data columns (total 10 columns):
0    100 non-null float64
1    100 non-null float64
2    100 non-null float64
3    100 non-null float64
4    100 non-null float64
5    100 non-null float64
6    100 non-null float64
7    100 non-null float64
8    100 non-null float64
9    100 non-null float64
dtypes: float64(10)
memory usage: 7.9 KB

Upvotes: 1

Related Questions