Package: dataframe-image
dataframe_imageA package to convert pandas DataFrames as images.Also convert Jupyter Notebooks to PDF and/or Markdown embedding dataframe as image into it.Exporting individual DataFramesdataframe_image has the ability to export both normal and styled DataFrames as images from within a Python script. Pass your normal or styled DataFrame to theexportfunction along with a file location to save it as an image.>>>importdataframe_imageasdfi>>>dfi.export(df_styled,'df_styled.png')You may also export directly from the DataFrame or styled DataFrame using thedfi.exportandexport_pngmethods, respectively.>>>df.dfi.export('df.png')>>>df_styled.export_png('df_styled.png')Here, an example of how exporting a DataFrame would look like in a notebook.Export Jupyter NotebookWhen converting Jupyter Notebooks to pdf using nbconvert, pandas DataFrames appear as either raw text or as simple LaTeX tables. The left side of the image below shows this representation.This package was first created to embed DataFrames into pdf and markdown documents as images so that they appear exactly as they do in Jupyter Notebooks, as seen from the right side of the image above. It has since added much more functionality.UsageUpon installation, the optionDataFrame as Image (PDF or Markdown)will appear in the menuFile -> Download as. Clicking this option will open up a new browser tab with a short form to be completed.InstallationInstall with either:pip install dataframe_imageconda install -c conda-forge dataframe_imageConfigurationtable_conversionWhen convert dataframe to image, we provide two kind of backend, browser or matplotlib. The default is browser, but you can change it by settingtable_conversionparameter to'matplotlib'.The major difference between these two backends is that browser backend will render the dataframe as it is in the notebook, while matplotlib backend can work without browser, can export all image format, eg.svg, and will be extremely fast.But currently matplotlib can only simulate default header and cells style, eg. background_gradient or font-size, any other css properties('width'/'height'/...) or additional element such asset_captionwill not work.dfi.export(df.style.background_gradient(),"df_style.png",table_conversion="matplotlib")Browser backendCurrent we provide 4 difference browser backend liberary:playwright,html2image,seleniumandchrome. The default ischrome.chrome, which means convert image with your local chromium based browser by command line.html2imageis a backup method forchrome, which usehtml2image.playwrightis a much more stable method, but you have to install playwright first.seleniumis a method that useFirefoxdriver. Sometimes chrome will make some breaking changes which break methods above,Firefoxwill be a good backup. Not stable and hard to install. But can be installed in Google Colab.Other parametersdfi.export(obj:pd.DataFrame,filename,fontsize=14,max_rows=None,max_cols=None,table_conversion:Literal["chrome","matplotlib","html2image","playwright","selenium"]="chrome",chrome_path=None,dpi=None,# enlarge your image，default is 100，set it larger will get a larger imageuse_mathjax=False,# enable mathjax support， which means you can use latex in your dataframe)PDF Conversion - LaTeX vs Chrome BrowserBy default, conversion to pdf happens via LaTeX, which you must have pre-installed on your machine. If you do not have the correct LaTeX installation, you'll need to select the Chrome Browser option to make the conversion.Conversion via Chrome browser is much quicker and will look very different than the LaTeX rendition. The chrome browser version will look nearly the same as it does in your browser, while the LaTeX version looking more like a book/article.Consultnbconvert's documentationto learn how to get latex installed correctly on your machine.More featuresBelow, is a description of other features from dataframe_image:Embeds all images from markdown cells (inline, reference, attachments, and<img>tags) into the pdfSaves the new documents anywhere in your filesystem and correctly link the resourcesConverts gifs to single-frame png files allowing them to be embedded into the pdfAs a Python Librarydataframe_image can also be used outside of the notebook as a normal Python library. In a separate Python script, import thedataframe_imagepackage and pass the file name of your notebook to theconvertfunction.>>>importdataframe_imageasdfi>>>dfi.convert('path/to/your_notebook.ipynb',to='pdf',use='latex',center_df=True,max_rows=30,max_cols=10,execute=False,save_notebook=False,limit=None,document_name=None,table_conversion='chrome',chrome_path=None,latex_command=None,output_dir=None,)By default, the new file(s) will be saved in the same directory where the notebook resides. Do not run this command within the same notebook that is being converted.From the Command LineThe command line tooldataframe_imagewill be available upon installation with the same options as theconvertfunction from above.dataframe_image--to=pdf"my notebook with dataframes.ipynb"--no-inputFinding Google ChromeYou must have Google Chrome (or Brave) installed in order for dataframe_image to work. The path to Chrome should automatically be found. If Chrome is not in a standard location, set it with thechrome_pathparameter.In Google ColabA Known Issue: When using dataframe_image with Google Colab, you can not use default Chrome convert method. You can settable_conversionparameter to'selenium'and it will callFirefoxdriver to convert the DataFrames to images.note: you have to install dependencies before use it:!apt install firefox firefox-geckodriver
!pip install dataframe_image selenium

...
df.dfi.export('df.png', table_conversion='selenium')Choose your converterIf you do not have Chrome installed or cannot get it to work properly, you can alternatively use matplotlib/selenium to convert the DataFrames to images. Select this option by setting thetable_conversionparameter to'selenium'or'matplotlib'.Publish to MediumClosely related to this package isjupyter_to_medium, which publishes your notebooks directly and quickly as Medium blog posts.DependenciesYou must have the following Python libraries installed:pandasnbconvertrequestsmatplotlibBeautifulSoupaiohttp