nbconvert to convert from notebook to Latex/PDF cuts off the dataframe - pdf

I have a notebook that displays lots of dataframe tables in HTML format. However when I used nbconvert to convert the notebook to latex and to PDF, some tables with wider body gets cut off. I have tried using pd.set_option('display.width', xxxx) but it didn't seem to work. It seems that the issue is not in the display of the pandas dataframe( the table is displayed just fine on the notebook ), but rather in converting the notebook to Latex/PDF. Is there anything I can do to resolve this problem?

Related

How to increase length of ouput table or dataframe in Jupyter Notebook?

I am working on the Jupyter notebook and have been facing issues in increasing the length of the output of the Jupyter Notebook. I can see the output as follows:
I tried increasing the default length of the columns in pandas with no success. Can you please help me with it?
If you were using the typical way to view a dataframe in Jupyter (see my puzzelment about your screenshot in my comments to your original post) it would be things like this:
adapted from answer to 'Pretty-print an entire Pandas Series / DataFrame'
with pd.option_context('display.max_rows', None, 'display.max_columns', None):
display(df)
(Note that will work with the text-based viewing, too. Note it uses print(df) in the answer to 'Pretty-print an entire Pandas Series / DataFrame'.
Adjust the 'display.max_colwidth' if you want the entire column text to show:
with pd.option_context('display.max_rows', None, 'display.max_columns', None,'display.max_colwidth', -1):
display(df)
(If you prefer text like you posted, replace display() with print()
Generally with the solutions above the view window in Jupyter will get scrollbars so you can navigate to view all still.
You can also set the number of rows to show to be lower to save space, see example here.
You may also be interested in Pandas dataframe hide index functionality? or Using python / Jupyter Notebook, how to prevent row numbers from printing?.
As pointed out here, setting some some global options is covered in the Pandas Documentation for top-level options.
For display() to work these days you don't need to do anything extra. But if your are using old Jupyter or it doesn't work then try adding towards the top of your notebook file and running the following as a cell first:
from IPython.display import display

Image as array in pandas dataframe

Images in PNG format in a variable (as array) are not being displayed in pandas dataframe.
The command lines:
display(HTML('df.html', df.to_html(escape=False ,formatters=format_dict)))
or
display(HTML(df.to_html(escape=False ,formatters=format_dict)))
should run using the following IPython packages
from IPython.display import display,HTML
from IPython.display import IFrame
However, these commands can only concatenate str (not "PngImageFile") to str. Also, I found in the stack overflow (How to write PNG image to string with the PIL?) that it is possible to solve this issue using a png file, but I need to add this png file into a pandas dataframe that does not work as well because a PngImageFile object is not callable.
How can I solve this issue?
Here is an example:
https://colab.research.google.com/drive/163jW-GoXKW4TckuIVK3_wjXB9wP11u0g?usp=sharing

The Jupyter do not show border lines and grey blocks

everybody. I learn NumPy and pandas with the Jupyter. When printing, it does not show borderlines and grey blocks. Example:
Should be:
How to solve it? Thank you very much, everybody.
The 'borderlines and grey blocks' view is a rendered HTML version of your dataframe.
You can either just use b as #Carlos Bergillos mentioned, or use
from IPython.display import display
display(b)
Please see other very similar questions:
Show DataFrame as table in iPython Notebook
Display DataFrame in Jupyter Notebook, Depending on a Condition
Display data in pandas dataframe

How to make pandas show the entire dataframe without cropping it by columns?

I am trying to represent cubic spline interpolation information for function f(x) as a dataframe.
When trying to print into a spyder, I find that the columns are being cut off. When trying to reproduce the output in Jupiter Lab, I got the same thing.
When I ran in ipython via terminal I got the desired full dataframe output.
I searched the integnet and tried the pandas commands setting options pd.set_options(), but nothing came of it.
I attach a screenshot with the output in ipython.
In Juputer can use:
from IPython.display import display, HTML
and instead of
print(dataframe)
use of in anyway place
display(HTML(dataframe.to_html()))
This will create a nice table.
Unfortunately, this will not work in the spyder. So you can try to adjust the width of the ipython were suggested. But in most cases this will make the output poorly or unreadable.
After trying the dataframe methods, I found what appears to be a cropping setting.
In Spyder I used:
pd.set_option('expand_frame_repr', False)
print(dataframe)
This method explains why increasing max_column didn't help me previously.
You can specify a maximum number for rows or columns using pd.set_options(display.max_columns=1000)
But you don't have to set an arbitrary value, but rather use None instead to make sure every size will be covered.
For rows, use:
pd.set_option('display.max_rows', None)
And for columns, use:
pd.set_option('display.max_columns', None)
It is a result of the display width. You can use the following set_options():
pd.set_options(display.width=1000) #make huge
You may also have to raise max columns but it should be smart enough to adjust automatically after you make width bigger:
pd.set_options(display.max_columns=None)

How to format numbers in Julia DataFrames notebook?

Using Julia and DataFrames.jl, Floats display in the notebook dataframe output like this:
5.97551e5
7.37884e5
3.10031e5
9.6429e5
2.40817e5
How would one get the notebook to display them like, for example,
5.97e5
7.37e5
3.10e5
9.64e5
2.40e5
Or using Formatting.jl with the format format(x,commas=true,autoscale=:finance,precision=2):
597.55k
737.88k
310.03k
964.29k
240.81k