| <!DOCTYPE html> |
| |
| <html lang="en" data-content_root="../../"> |
| <head> |
| <meta charset="utf-8" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" /> |
| |
| <title>HTML Rendering in Jupyter — Apache Arrow DataFusion documentation</title> |
| |
| <link href="../../_static/styles/theme.css?digest=1999514e3f237ded88cf" rel="stylesheet"> |
| <link href="../../_static/styles/pydata-sphinx-theme.css?digest=1999514e3f237ded88cf" rel="stylesheet"> |
| |
| |
| <link rel="stylesheet" |
| href="../../_static/vendor/fontawesome/5.13.0/css/all.min.css"> |
| <link rel="preload" as="font" type="font/woff2" crossorigin |
| href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2"> |
| <link rel="preload" as="font" type="font/woff2" crossorigin |
| href="../../_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2"> |
| |
| |
| |
| |
| |
| <link rel="stylesheet" type="text/css" href="../../_static/pygments.css?v=8f2a1f02" /> |
| <link rel="stylesheet" type="text/css" href="../../_static/styles/pydata-sphinx-theme.css?v=1140d252" /> |
| <link rel="stylesheet" type="text/css" href="../../_static/graphviz.css?v=4ae1632d" /> |
| <link rel="stylesheet" type="text/css" href="../../_static/theme_overrides.css?v=dca7052a" /> |
| |
| <link rel="preload" as="script" href="../../_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf"> |
| |
| <script src="../../_static/documentation_options.js?v=8a448e45"></script> |
| <script src="../../_static/doctools.js?v=9bcbadda"></script> |
| <script src="../../_static/sphinx_highlight.js?v=dc90522c"></script> |
| <link rel="index" title="Index" href="../../genindex.html" /> |
| <link rel="search" title="Search" href="../../search.html" /> |
| <link rel="next" title="Common Operations" href="../common-operations/index.html" /> |
| <link rel="prev" title="DataFrames" href="index.html" /> |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| <meta name="docsearch:language" content="en"> |
| |
| |
| <!-- Google Analytics --> |
| |
| </head> |
| <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80"> |
| |
| <div class="container-fluid" id="banner"></div> |
| |
| |
| |
| |
| <div class="container-xl"> |
| <div class="row"> |
| |
| |
| <!-- Only show if we have sidebars configured, else just a small margin --> |
| <div class="col-12 col-md-3 bd-sidebar"> |
| <div class="sidebar-start-items"> |
| <a class="navbar-brand" href="../../index.html"> |
| <img src="../../_static/images/2x_bgwhite_original.png" class="logo" alt="logo"> |
| </a> |
| |
| <form class="bd-search d-flex align-items-center" action="../../search.html" method="get"> |
| <i class="icon fas fa-search"></i> |
| <input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" > |
| </form> |
| |
| <nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation"> |
| <div class="bd-toc-item active"> |
| |
| <p aria-level="2" class="caption" role="heading"> |
| <span class="caption-text"> |
| LINKS |
| </span> |
| </p> |
| <ul class="nav bd-sidenav"> |
| <li class="toctree-l1"> |
| <a class="reference external" href="https://github.com/apache/datafusion-python"> |
| Github and Issue Tracker |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference external" href="https://docs.rs/datafusion/latest/datafusion/"> |
| Rust's API Docs |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference external" href="https://github.com/apache/datafusion/blob/main/CODE_OF_CONDUCT.md"> |
| Code of conduct |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference external" href="https://github.com/apache/datafusion-python/tree/main/examples"> |
| Examples |
| </a> |
| </li> |
| </ul> |
| <p aria-level="2" class="caption" role="heading"> |
| <span class="caption-text"> |
| USER GUIDE |
| </span> |
| </p> |
| <ul class="current nav bd-sidenav"> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../introduction.html"> |
| Introduction |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../basics.html"> |
| Concepts |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../data-sources.html"> |
| Data Sources |
| </a> |
| </li> |
| <li class="toctree-l1 current active has-children"> |
| <a class="reference internal" href="index.html"> |
| DataFrames |
| </a> |
| <input checked="" class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" type="checkbox"/> |
| <label for="toctree-checkbox-1"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul class="current"> |
| <li class="toctree-l2 current active"> |
| <a class="current reference internal" href="#"> |
| HTML Rendering in Jupyter |
| </a> |
| </li> |
| </ul> |
| </li> |
| <li class="toctree-l1 has-children"> |
| <a class="reference internal" href="../common-operations/index.html"> |
| Common Operations |
| </a> |
| <input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" type="checkbox"/> |
| <label for="toctree-checkbox-2"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/views.html"> |
| Registering Views |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/basic-info.html"> |
| Basic Operations |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/select-and-filter.html"> |
| Column Selections |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/expressions.html"> |
| Expressions |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/joins.html"> |
| Joins |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/functions.html"> |
| Functions |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/aggregations.html"> |
| Aggregation |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/windows.html"> |
| Window Functions |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../common-operations/udf-and-udfa.html"> |
| User-Defined Functions |
| </a> |
| </li> |
| </ul> |
| </li> |
| <li class="toctree-l1 has-children"> |
| <a class="reference internal" href="../io/index.html"> |
| IO |
| </a> |
| <input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" type="checkbox"/> |
| <label for="toctree-checkbox-3"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/arrow.html"> |
| Arrow |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/avro.html"> |
| Avro |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/csv.html"> |
| CSV |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/json.html"> |
| JSON |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/parquet.html"> |
| Parquet |
| </a> |
| </li> |
| <li class="toctree-l2"> |
| <a class="reference internal" href="../io/table_provider.html"> |
| Custom Table Provider |
| </a> |
| </li> |
| </ul> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../configuration.html"> |
| Configuration |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../sql.html"> |
| SQL |
| </a> |
| </li> |
| </ul> |
| <p aria-level="2" class="caption" role="heading"> |
| <span class="caption-text"> |
| CONTRIBUTOR GUIDE |
| </span> |
| </p> |
| <ul class="nav bd-sidenav"> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../../contributor-guide/introduction.html"> |
| Introduction |
| </a> |
| </li> |
| <li class="toctree-l1"> |
| <a class="reference internal" href="../../contributor-guide/ffi.html"> |
| Python Extensions |
| </a> |
| </li> |
| </ul> |
| <p aria-level="2" class="caption" role="heading"> |
| <span class="caption-text"> |
| API |
| </span> |
| </p> |
| <ul class="nav bd-sidenav"> |
| <li class="toctree-l1 has-children"> |
| <a class="reference internal" href="../../autoapi/index.html"> |
| API Reference |
| </a> |
| <input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" type="checkbox"/> |
| <label for="toctree-checkbox-4"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul> |
| <li class="toctree-l2 has-children"> |
| <a class="reference internal" href="../../autoapi/datafusion/index.html"> |
| datafusion |
| </a> |
| <input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" type="checkbox"/> |
| <label for="toctree-checkbox-5"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/catalog/index.html"> |
| datafusion.catalog |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/context/index.html"> |
| datafusion.context |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/dataframe/index.html"> |
| datafusion.dataframe |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/dataframe_formatter/index.html"> |
| datafusion.dataframe_formatter |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/expr/index.html"> |
| datafusion.expr |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/functions/index.html"> |
| datafusion.functions |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/html_formatter/index.html"> |
| datafusion.html_formatter |
| </a> |
| </li> |
| <li class="toctree-l3 has-children"> |
| <a class="reference internal" href="../../autoapi/datafusion/input/index.html"> |
| datafusion.input |
| </a> |
| <input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" type="checkbox"/> |
| <label for="toctree-checkbox-6"> |
| <i class="fas fa-chevron-down"> |
| </i> |
| </label> |
| <ul> |
| <li class="toctree-l4"> |
| <a class="reference internal" href="../../autoapi/datafusion/input/base/index.html"> |
| datafusion.input.base |
| </a> |
| </li> |
| <li class="toctree-l4"> |
| <a class="reference internal" href="../../autoapi/datafusion/input/location/index.html"> |
| datafusion.input.location |
| </a> |
| </li> |
| </ul> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/io/index.html"> |
| datafusion.io |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/object_store/index.html"> |
| datafusion.object_store |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/plan/index.html"> |
| datafusion.plan |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/record_batch/index.html"> |
| datafusion.record_batch |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/substrait/index.html"> |
| datafusion.substrait |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/unparser/index.html"> |
| datafusion.unparser |
| </a> |
| </li> |
| <li class="toctree-l3"> |
| <a class="reference internal" href="../../autoapi/datafusion/user_defined/index.html"> |
| datafusion.user_defined |
| </a> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| </li> |
| </ul> |
| |
| |
| </div> |
| </nav> |
| </div> |
| <div class="sidebar-end-items"> |
| </div> |
| </div> |
| |
| |
| |
| |
| <div class="d-none d-xl-block col-xl-2 bd-toc"> |
| |
| |
| <div class="toc-item"> |
| |
| <div class="tocsection onthispage pt-5 pb-3"> |
| <i class="fas fa-list"></i> On this page |
| </div> |
| |
| <nav id="bd-toc-nav"> |
| <ul class="visible nav section-nav flex-column"> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#basic-html-rendering"> |
| Basic HTML Rendering |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#customizing-html-rendering"> |
| Customizing HTML Rendering |
| </a> |
| <ul class="visible nav section-nav flex-column"> |
| <li class="toc-h3 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#configuring-the-html-formatter"> |
| Configuring the HTML Formatter |
| </a> |
| </li> |
| </ul> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#custom-style-providers"> |
| Custom Style Providers |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#performance-optimization-with-shared-styles"> |
| Performance Optimization with Shared Styles |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#creating-a-custom-formatter"> |
| Creating a Custom Formatter |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#managing-formatters"> |
| Managing Formatters |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#contextual-formatting"> |
| Contextual Formatting |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#memory-and-display-controls"> |
| Memory and Display Controls |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#best-practices"> |
| Best Practices |
| </a> |
| </li> |
| <li class="toc-h2 nav-item toc-entry"> |
| <a class="reference internal nav-link" href="#additional-resources"> |
| Additional Resources |
| </a> |
| </li> |
| </ul> |
| |
| </nav> |
| </div> |
| |
| <div class="toc-item"> |
| |
| </div> |
| |
| |
| </div> |
| |
| |
| |
| |
| |
| |
| <main class="col-12 col-md-9 col-xl-7 py-md-5 pl-md-5 pr-md-4 bd-content" role="main"> |
| |
| <div> |
| |
| <section id="html-rendering-in-jupyter"> |
| <h1>HTML Rendering in Jupyter<a class="headerlink" href="#html-rendering-in-jupyter" title="Link to this heading">¶</a></h1> |
| <p>When working in Jupyter notebooks or other environments that support rich HTML display, |
| DataFusion DataFrames automatically render as nicely formatted HTML tables. This functionality |
| is provided by the <code class="docutils literal notranslate"><span class="pre">_repr_html_</span></code> method, which is automatically called by Jupyter to provide |
| a richer visualization than plain text output.</p> |
| <section id="basic-html-rendering"> |
| <h2>Basic HTML Rendering<a class="headerlink" href="#basic-html-rendering" title="Link to this heading">¶</a></h2> |
| <p>In a Jupyter environment, simply displaying a DataFrame object will trigger HTML rendering:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># Will display as HTML table in Jupyter</span> |
| <span class="n">df</span> |
| |
| <span class="c1"># Explicit display also uses HTML rendering</span> |
| <span class="n">display</span><span class="p">(</span><span class="n">df</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="customizing-html-rendering"> |
| <h2>Customizing HTML Rendering<a class="headerlink" href="#customizing-html-rendering" title="Link to this heading">¶</a></h2> |
| <p>DataFusion provides extensive customization options for HTML table rendering through the |
| <code class="docutils literal notranslate"><span class="pre">datafusion.html_formatter</span></code> module.</p> |
| <section id="configuring-the-html-formatter"> |
| <h3>Configuring the HTML Formatter<a class="headerlink" href="#configuring-the-html-formatter" title="Link to this heading">¶</a></h3> |
| <p>You can customize how DataFrames are rendered by configuring the formatter:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">configure_formatter</span> |
| |
| <span class="c1"># Change the default styling</span> |
| <span class="n">configure_formatter</span><span class="p">(</span> |
| <span class="n">max_cell_length</span><span class="o">=</span><span class="mi">25</span><span class="p">,</span> <span class="c1"># Maximum characters in a cell before truncation</span> |
| <span class="n">max_width</span><span class="o">=</span><span class="mi">1000</span><span class="p">,</span> <span class="c1"># Maximum width in pixels</span> |
| <span class="n">max_height</span><span class="o">=</span><span class="mi">300</span><span class="p">,</span> <span class="c1"># Maximum height in pixels</span> |
| <span class="n">max_memory_bytes</span><span class="o">=</span><span class="mi">2097152</span><span class="p">,</span> <span class="c1"># Maximum memory for rendering (2MB)</span> |
| <span class="n">min_rows_display</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span> <span class="c1"># Minimum number of rows to display</span> |
| <span class="n">repr_rows</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="c1"># Number of rows to display in __repr__</span> |
| <span class="n">enable_cell_expansion</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span><span class="c1"># Allow expanding truncated cells</span> |
| <span class="n">custom_css</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="c1"># Additional custom CSS</span> |
| <span class="n">show_truncation_message</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="c1"># Show message when data is truncated</span> |
| <span class="n">style_provider</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="c1"># Custom styling provider</span> |
| <span class="n">use_shared_styles</span><span class="o">=</span><span class="kc">True</span> <span class="c1"># Share styles across tables</span> |
| <span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>The formatter settings affect all DataFrames displayed after configuration.</p> |
| </section> |
| </section> |
| <section id="custom-style-providers"> |
| <h2>Custom Style Providers<a class="headerlink" href="#custom-style-providers" title="Link to this heading">¶</a></h2> |
| <p>For advanced styling needs, you can create a custom style provider:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">StyleProvider</span><span class="p">,</span> <span class="n">configure_formatter</span> |
| |
| <span class="k">class</span><span class="w"> </span><span class="nc">MyStyleProvider</span><span class="p">(</span><span class="n">StyleProvider</span><span class="p">):</span> |
| <span class="k">def</span><span class="w"> </span><span class="nf">get_table_styles</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span> |
| <span class="k">return</span> <span class="p">{</span> |
| <span class="s2">"table"</span><span class="p">:</span> <span class="s2">"border-collapse: collapse; width: 100%;"</span><span class="p">,</span> |
| <span class="s2">"th"</span><span class="p">:</span> <span class="s2">"background-color: #007bff; color: white; padding: 8px; text-align: left;"</span><span class="p">,</span> |
| <span class="s2">"td"</span><span class="p">:</span> <span class="s2">"border: 1px solid #ddd; padding: 8px;"</span><span class="p">,</span> |
| <span class="s2">"tr:nth-child(even)"</span><span class="p">:</span> <span class="s2">"background-color: #f2f2f2;"</span><span class="p">,</span> |
| <span class="p">}</span> |
| |
| <span class="k">def</span><span class="w"> </span><span class="nf">get_value_styles</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">dtype</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span> |
| <span class="w"> </span><span class="sd">"""Return custom styles for specific values"""</span> |
| <span class="k">if</span> <span class="n">dtype</span> <span class="o">==</span> <span class="s2">"float"</span> <span class="ow">and</span> <span class="n">value</span> <span class="o"><</span> <span class="mi">0</span><span class="p">:</span> |
| <span class="k">return</span> <span class="s2">"color: red;"</span> |
| <span class="k">return</span> <span class="kc">None</span> |
| |
| <span class="c1"># Apply the custom style provider</span> |
| <span class="n">configure_formatter</span><span class="p">(</span><span class="n">style_provider</span><span class="o">=</span><span class="n">MyStyleProvider</span><span class="p">())</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="performance-optimization-with-shared-styles"> |
| <h2>Performance Optimization with Shared Styles<a class="headerlink" href="#performance-optimization-with-shared-styles" title="Link to this heading">¶</a></h2> |
| <p>The <code class="docutils literal notranslate"><span class="pre">use_shared_styles</span></code> parameter (enabled by default) optimizes performance when displaying |
| multiple DataFrames in notebook environments:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">StyleProvider</span><span class="p">,</span> <span class="n">configure_formatter</span> |
| <span class="c1"># Default: Use shared styles (recommended for notebooks)</span> |
| <span class="n">configure_formatter</span><span class="p">(</span><span class="n">use_shared_styles</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span> |
| |
| <span class="c1"># Disable shared styles (each DataFrame includes its own styles)</span> |
| <span class="n">configure_formatter</span><span class="p">(</span><span class="n">use_shared_styles</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>When <code class="docutils literal notranslate"><span class="pre">use_shared_styles=True</span></code>: |
| - CSS styles and JavaScript are included only once per notebook session |
| - This reduces HTML output size and prevents style duplication |
| - Improves rendering performance with many DataFrames |
| - Applies consistent styling across all DataFrames</p> |
| </section> |
| <section id="creating-a-custom-formatter"> |
| <h2>Creating a Custom Formatter<a class="headerlink" href="#creating-a-custom-formatter" title="Link to this heading">¶</a></h2> |
| <p>For complete control over rendering, you can implement a custom formatter:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">Formatter</span><span class="p">,</span> <span class="n">get_formatter</span> |
| |
| <span class="k">class</span><span class="w"> </span><span class="nc">MyFormatter</span><span class="p">(</span><span class="n">Formatter</span><span class="p">):</span> |
| <span class="k">def</span><span class="w"> </span><span class="nf">format_html</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">batches</span><span class="p">,</span> <span class="n">schema</span><span class="p">,</span> <span class="n">has_more</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">table_uuid</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span> |
| <span class="c1"># Create your custom HTML here</span> |
| <span class="n">html</span> <span class="o">=</span> <span class="s2">"<div class='my-custom-table'>"</span> |
| <span class="c1"># ... formatting logic ...</span> |
| <span class="n">html</span> <span class="o">+=</span> <span class="s2">"</div>"</span> |
| <span class="k">return</span> <span class="n">html</span> |
| |
| <span class="c1"># Set as the global formatter</span> |
| <span class="n">configure_formatter</span><span class="p">(</span><span class="n">formatter_class</span><span class="o">=</span><span class="n">MyFormatter</span><span class="p">)</span> |
| |
| <span class="c1"># Or use the formatter just for specific operations</span> |
| <span class="n">formatter</span> <span class="o">=</span> <span class="n">get_formatter</span><span class="p">()</span> |
| <span class="n">custom_html</span> <span class="o">=</span> <span class="n">formatter</span><span class="o">.</span><span class="n">format_html</span><span class="p">(</span><span class="n">batches</span><span class="p">,</span> <span class="n">schema</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="managing-formatters"> |
| <h2>Managing Formatters<a class="headerlink" href="#managing-formatters" title="Link to this heading">¶</a></h2> |
| <p>Reset to default formatting:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">reset_formatter</span> |
| |
| <span class="c1"># Reset to default settings</span> |
| <span class="n">reset_formatter</span><span class="p">()</span> |
| </pre></div> |
| </div> |
| <p>Get the current formatter settings:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">get_formatter</span> |
| |
| <span class="n">formatter</span> <span class="o">=</span> <span class="n">get_formatter</span><span class="p">()</span> |
| <span class="nb">print</span><span class="p">(</span><span class="n">formatter</span><span class="o">.</span><span class="n">max_rows</span><span class="p">)</span> |
| <span class="nb">print</span><span class="p">(</span><span class="n">formatter</span><span class="o">.</span><span class="n">theme</span><span class="p">)</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="contextual-formatting"> |
| <h2>Contextual Formatting<a class="headerlink" href="#contextual-formatting" title="Link to this heading">¶</a></h2> |
| <p>You can also use a context manager to temporarily change formatting settings:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">datafusion.html_formatter</span><span class="w"> </span><span class="kn">import</span> <span class="n">formatting_context</span> |
| |
| <span class="c1"># Default formatting</span> |
| <span class="n">df</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> |
| |
| <span class="c1"># Temporarily use different formatting</span> |
| <span class="k">with</span> <span class="n">formatting_context</span><span class="p">(</span><span class="n">max_rows</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="n">theme</span><span class="o">=</span><span class="s2">"dark"</span><span class="p">):</span> |
| <span class="n">df</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> <span class="c1"># Will use the temporary settings</span> |
| |
| <span class="c1"># Back to default formatting</span> |
| <span class="n">df</span><span class="o">.</span><span class="n">show</span><span class="p">()</span> |
| </pre></div> |
| </div> |
| </section> |
| <section id="memory-and-display-controls"> |
| <h2>Memory and Display Controls<a class="headerlink" href="#memory-and-display-controls" title="Link to this heading">¶</a></h2> |
| <p>You can control how much data is displayed and how much memory is used for rendering:</p> |
| <div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">configure_formatter</span><span class="p">(</span> |
| <span class="n">max_memory_bytes</span><span class="o">=</span><span class="mi">4</span> <span class="o">*</span> <span class="mi">1024</span> <span class="o">*</span> <span class="mi">1024</span><span class="p">,</span> <span class="c1"># 4MB maximum memory for display</span> |
| <span class="n">min_rows_display</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="c1"># Always show at least 50 rows</span> |
| <span class="n">repr_rows</span><span class="o">=</span><span class="mi">20</span> <span class="c1"># Show 20 rows in __repr__ output</span> |
| <span class="p">)</span> |
| </pre></div> |
| </div> |
| <p>These parameters help balance comprehensive data display against performance considerations.</p> |
| </section> |
| <section id="best-practices"> |
| <h2>Best Practices<a class="headerlink" href="#best-practices" title="Link to this heading">¶</a></h2> |
| <ol class="arabic simple"> |
| <li><p><strong>Global Configuration</strong>: Use <code class="docutils literal notranslate"><span class="pre">configure_formatter()</span></code> at the beginning of your notebook to set up consistent formatting for all DataFrames.</p></li> |
| <li><p><strong>Memory Management</strong>: Set appropriate <code class="docutils literal notranslate"><span class="pre">max_memory_bytes</span></code> limits to prevent performance issues with large datasets.</p></li> |
| <li><p><strong>Shared Styles</strong>: Keep <code class="docutils literal notranslate"><span class="pre">use_shared_styles=True</span></code> (default) for better performance in notebooks with multiple DataFrames.</p></li> |
| <li><p><strong>Reset When Needed</strong>: Call <code class="docutils literal notranslate"><span class="pre">reset_formatter()</span></code> when you want to start fresh with default settings.</p></li> |
| <li><p><strong>Cell Expansion</strong>: Use <code class="docutils literal notranslate"><span class="pre">enable_cell_expansion=True</span></code> when cells might contain longer content that users may want to see in full.</p></li> |
| </ol> |
| </section> |
| <section id="additional-resources"> |
| <h2>Additional Resources<a class="headerlink" href="#additional-resources" title="Link to this heading">¶</a></h2> |
| <ul class="simple"> |
| <li><p><a class="reference internal" href="index.html"><span class="doc">DataFrames</span></a> - Complete guide to using DataFrames</p></li> |
| <li><p><a class="reference internal" href="../io/index.html"><span class="doc">IO</span></a> - I/O Guide for reading data from various sources</p></li> |
| <li><p><a class="reference internal" href="../data-sources.html"><span class="doc">Data Sources</span></a> - Comprehensive data sources guide</p></li> |
| <li><p><a class="reference internal" href="../io/csv.html#io-csv"><span class="std std-ref">CSV</span></a> - CSV file reading</p></li> |
| <li><p><a class="reference internal" href="../io/parquet.html#io-parquet"><span class="std std-ref">Parquet</span></a> - Parquet file reading</p></li> |
| <li><p><a class="reference internal" href="../io/json.html#io-json"><span class="std std-ref">JSON</span></a> - JSON file reading</p></li> |
| <li><p><a class="reference internal" href="../io/avro.html#io-avro"><span class="std std-ref">Avro</span></a> - Avro file reading</p></li> |
| <li><p><a class="reference internal" href="../io/table_provider.html#io-custom-table-provider"><span class="std std-ref">Custom Table Provider</span></a> - Custom table providers</p></li> |
| <li><p><a class="reference external" href="https://arrow.apache.org/datafusion-python/api/index.html">API Reference</a> - Full API reference</p></li> |
| </ul> |
| </section> |
| </section> |
| |
| |
| </div> |
| |
| |
| <!-- Previous / next buttons --> |
| <div class='prev-next-area'> |
| <a class='left-prev' id="prev-link" href="index.html" title="previous page"> |
| <i class="fas fa-angle-left"></i> |
| <div class="prev-next-info"> |
| <p class="prev-next-subtitle">previous</p> |
| <p class="prev-next-title">DataFrames</p> |
| </div> |
| </a> |
| <a class='right-next' id="next-link" href="../common-operations/index.html" title="next page"> |
| <div class="prev-next-info"> |
| <p class="prev-next-subtitle">next</p> |
| <p class="prev-next-title">Common Operations</p> |
| </div> |
| <i class="fas fa-angle-right"></i> |
| </a> |
| </div> |
| |
| </main> |
| |
| |
| </div> |
| </div> |
| |
| <script src="../../_static/scripts/pydata-sphinx-theme.js?digest=1999514e3f237ded88cf"></script> |
| |
| <!-- Based on pydata_sphinx_theme/footer.html --> |
| <footer class="footer mt-5 mt-md-0"> |
| <div class="container"> |
| |
| <div class="footer-item"> |
| <p class="copyright"> |
| © Copyright 2019-2024, Apache Software Foundation.<br> |
| </p> |
| </div> |
| |
| <div class="footer-item"> |
| <p class="sphinx-version"> |
| Created using <a href="http://sphinx-doc.org/">Sphinx</a> 8.1.3.<br> |
| </p> |
| </div> |
| |
| <div class="footer-item"> |
| <p>Apache Arrow DataFusion, Arrow DataFusion, Apache, the Apache feather logo, and the Apache Arrow DataFusion project logo</p> |
| <p>are either registered trademarks or trademarks of The Apache Software Foundation in the United States and other countries.</p> |
| </div> |
| </div> |
| </footer> |
| |
| |
| </body> |
| </html> |