Pretty print a dataframe
Problem
When you print a dataframe into the console, you normally get only a few columns out.
In this case, we have 12 columns, but when printing the content we see an ellipsis, and only a few columns are shown.
Solution
A quick way of solving this is by modifying the printing options:
with pd.option_context('display.max_columns', None, 'display.width', None):
print(df1)
It works like this:
(’Option to modify’, Value to assign, ’Option to modify’, Value to assign, … )
In this case, we have added the following options:
- display.max_columns = None: This will print all the columns without truncating them.
- display.width = None - This will detect the width of the screen that the content is being printed.
You can find a list of all available options here:
https://pandas.pydata.org/docs/reference/api/pandas.set_option.html
Source:
https://pandas.pydata.org/docs/reference/api/pandas.option_context.html