How to Print All Rows of a Pandas DataFrame
Suppose we have a very large DataFrame that we want to print.
print(df)
DataFrame truncate issue
By default, our DataFrame output is truncated (and for good reason).
A B ... Y Z
0 data1 1 ... 1 1
1 data2 2 ... 2 2
2 data3 3 ... 3 3
3 data4 4 ... 4 4
4 data5 5 ... 5 5
.. ... .. ... .. ..
58 data58 6 ... 6 6
59 data59 7 ... 7 7
60 data60 8 ... 8 8
61 data61 9 ... 9 9
62 data62 10 ... 10 10
[63 rows x 26 columns]
However, there are valid scenarios in which we might need to print the untruncated version of our DataFrame.
Untruncate using set_option()
Pandas has a set_option()
that will allow us to set display
parameters.
The following four lines will allow us to avoid truncation in DataFrame outputs.
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.width', None)
pd.set_option('display.max_colwidth', -1)
display.max_rows
sets the maximum number of rows displayed (default is10
)display.max_columns
sets the maximum number of columns displayed (default is4
)display.width
sets the width of the display in characters. When set toNone
, Pandas will correctly auto-detect the widthdisplay.max_colwidth
sets the maximum width of columns. Cells of this length or longer will be truncated with an ellipsis.
Read more about available parameters for
set_options()
in the Pandas documentation.