Using the following functions, I already managed to prevent truncation in the output in my notebook:
pd.set_option('display.max_colwidth', 200)
pd.set_option('display.max_columns', 0)
However, it still breaks long lines within some cells (not truncates!). How can I prevent it from doing that?
(I don't care how wide the total table will be, because I can simply scroll in the output of the notebook cell ...)
for me worked pandas.set_option('display.expand_frame_repr', False)
as suggested by @EdChum.
import pandas
matrix = [[None]*5]*4
matrix[1][1] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut"
matrix[1][4] = matrix[1][1]
print pandas.DataFrame(matrix) # will print the matrix,
# column 4 is completely underneath the other 3 columns with all rows
pandas.set_option('display.expand_frame_repr', False)
print pandas.DataFrame(matrix) # prints only one table (no break of columns)
This worked for me, I'm using python 2.7, and tested it with 3.6 on the Pycharm IDE.
try:
df = pd.read_excel(file,sheet_name="sheet", inplace=True, usecols="A,C:E")
with pd.option_context('display.max_rows', 300, 'display.max_columns', 7, 'display.expand_frame_repr', False):
print(df)
except:
print ('failed')
However, for the Jupyter Notebooks, I believe this is the syntax:
pd.options.display.max_rows
pd.set_option('display.max_colwidth', -1)
pd.DataFrame({'string_x': string_x}, index = [0])
None of the solutions here worked in jupyter for me, what worked was appealing to CSS:
from IPython.display import HTML
HTML(f"<style>td{white-space: nowrap !important;}</style>")
I've not tested but this may work too:
df.style.set_table_styles([{'selector': 'td', 'props': 'white-space: nowrap !important;'}])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With