Reputation: 748
I have a Jupyter Notebook where when I run:
df.head()
The resulting output is a dataframe with many, many columns therefore resulting in a vertical scrollbar.
This would be fine if I were able to privately share the data as a .html or an .ipynb file, but I need to download it as a static pdf. As a pdf, these data frames are simply getting cut off.
This is a very long notebook with several instances where this happens. What can I do to remedy this?
Thank you
Upvotes: 2
Views: 5180
Reputation: 68
Please clarify:
edit sorry, just realised you must be using:
pd.set_option('display.max_columns', 100)
'I need to download it as a static pdf.'
edit: As you discovered, and stated in the comments, the easiest thing to do will be to just print the df.
if you want to stay in the notebook and control the number of columns that get printed (max of 15 before it automatically wraps)
# make up a wide empty datframe
col_names = ['a_' + str(x) for x in range(37)]
df = pd.DataFrame(columns=col_names, index=range(10))
section_width = 10 # set the number of columns you want to print - not that more than 15
for section_no in range(int(df.shape[1] / section_width + 1)) :
print(df.iloc[0:5, section_no * section_width : (section_no + 1) * section_width])
# if you want more or less than 5 rows then adust the numbers in .iloc[0:5]
Anyway, if you can give us some more detail on what you are trying to achieve we might be better able to help - Goodluck
Upvotes: 1
Reputation: 922
Have you tried to toggle the scrolling in the Cell options ? Like such:
Can be done for individual cells and all cells as you see in my screenshot.
Upvotes: 4