If you set the display.max_colwidth
option, the information will be displayed fully:
pd.set_option('display.max_columns', None)
id
(second argument) can fully show the columns.
While pd.set_option('display.max_columns', None)
sets the number of the maximum columns shown, the option pd.set_option('display.max_colwidth', -1)
sets the maximum width of each single field.
For my purposes I wrote a small helper function to fully print huge data frames without affecting the rest of the code. It also reformats float numbers and sets the virtual display width. You may adopt it for your use cases.
def print_full(x):pd.set_option('display.max_rows', None)pd.set_option('display.max_columns', None)pd.set_option('display.width', 2000)pd.set_option('display.float_format', '{:20,.2f}'.format)pd.set_option('display.max_colwidth', None)print(x)pd.reset_option('display.max_rows')pd.reset_option('display.max_columns')pd.reset_option('display.width')pd.reset_option('display.float_format')pd.reset_option('display.max_colwidth')
Whenever I need this for just one cell, I use this:
with pd.option_context('display.max_colwidth', None):display(df)
Try this too:
pd.set_option("max_columns", None) # show all colspd.set_option('max_colwidth', None) # show full width of showing colspd.set_option("expand_frame_repr", False) # print cols side by side as it's supposed to be
The following code results in the error below:
pd.set_option('display.max_colwidth', -1)
FutureWarning: Passing a negative integer is deprecated in version 1.0 and will not be supported in future version. Instead, use None to not limit the column width.
Instead, use:
pd.set_option('display.max_colwidth', None)
This accomplishes the task and complies with versions of Pandas following version 1.0.
Another way of viewing the full content of the cells in a Pandas dataframe is to use IPython's display functions:
from IPython.display import HTMLHTML(df.to_html())
Display the full dataframe for a specific cell:
import pandas as pdwith pd.option_context('display.max_colwidth', None,'display.max_columns', None,'display.max_rows', None):display(df)
The method above can be extended with more options.
Updated helper function from Karl Adler:
def display_full(x):with pd.option_context('display.max_rows', None,'display.max_columns', None,'display.width', 2000,'display.float_format', '{:20,.2f}'.format,'display.max_colwidth', None):display(x)
Change display options for all cells:
pd.set_option('display.max_colwidth', None)pd.set_option('display.max_rows', None)pd.set_option('display.max_columns', None)display(df)
For those looking to do this in Dask:
I could not find a similar option in Dask, but if I simply do this in same notebook for Pandas it works for Dask too.
import pandas as pdimport dask.dataframe as ddpd.set_option('display.max_colwidth', -1) # This will set the no truncate for Pandas as well as for Dask. I am not sure how it does for Dask though, but it works.train_data = dd.read_csv('./data/train.csv')train_data.head(5)
For those who like to reduce typing (i.e., everyone!): pd.set_option('max_colwidth', None)
does the same thing
I would like to offer other methods. If you don't want to always set it as default.
# First methodlist(df.itertuples()) # This would force pandas to explicitly display your dataframe, however it's not that beautiful# Second methodimport tabulateprint(tabulate(df, tablefmt='psql', headers='keys')) # `headers` are your columns, `keys` are the current columns# `psql` is one type of format for tabulate to organize before, you could pick other format you like in the documentation