Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(3, 3), columns=list("ABC"))
df.style.format('$\\beta=$ {:.2%}').set_caption('This is the result with $\\alpha=5$')
Issue Description
When the code above is executed in a Jupyter notebook inside of VS code, the latex is not rendered:
Expected Behavior
The expected behavior is the following:
Notably, this output was produced by using VS Code Export to HTML (which works as expected).
Installed Versions
Comment From: jrmagers
Also reported here: https://github.com/executablebooks/jupyter-book)](https://github.com/executablebooks/jupyter-book/issues/1826
Comment From: rhshadrach
From the link above, pandas behaves correctly in jupyter-lab. Is there any reason to suspect this is an issue with pandas?
Comment From: jrmagers
From the link above, pandas behaves correctly in jupyter-lab. Is there any reason to suspect this is an issue with pandas?
The only (possible) reason I believe is that it used to work in the past (with an older version of pandas). That's my own observation that I should probably look into.
Comment From: rhshadrach
with an older version of pandas
What version?
Comment From: attack68
Agree with @rhshadrach. If this renders in one system it is not pandas issue.
Have you tried using another math mode identifier. Perhaps VSCode has changed/updated? Is it an option that is configurable in VSCode. Do you need a mathjax addin installed to VSCode?
df = pd.DataFrame(np.random.randn(1, 1), columns=list("A"))
print(df.style.format('\( \\beta= \) {:.2%}').set_caption('This is the result with $\\alpha=5$').to_latex())
\begin{table}
\caption{This is the result with $\alpha=5$}
\begin{tabular}{lr}
& A \\
0 & \( \beta= \) -156.96% \\
\end{tabular}
\end{table}
This pandas output is correct.
print(df.style.format('$\\beta=$ {:.2%}').set_caption('This is the result with $\\alpha=5$').to_html())
<style type="text/css">
</style>
<table id="T_94ee7">
<caption>This is the result with $\alpha=5$</caption>
<thead>
<tr>
<th class="blank level0" > </th>
<th id="T_94ee7_level0_col0" class="col_heading level0 col0" >A</th>
</tr>
</thead>
<tbody>
<tr>
<th id="T_94ee7_level0_row0" class="row_heading level0 row0" >0</th>
<td id="T_94ee7_row0_col0" class="data row0 col0" >\( \beta= \) -156.96%</td>
</tr>
</tbody>
</table>
Are you aware that some browsers / renderers detect pandas dataframes from the HTML CSS class that pandas has attached? Google Colab used to need class="dataframe"
but I believe that is now fixed and remove.
You can try:
df.style
.format('$\\beta=$ {:.2%}')
.set_caption('This is the result with $\\alpha=5$')
.set_table_attributes('class="dataframe"')
This has fixed other problems: see here
Comment From: rhshadrach
@jrmagers - friendly ping, it would be helpful to know if @attack68's suggestion above fixes the issue for you.
Comment From: jrmagers
I tried .set_table_attributes('class="dataframe"')
and I also tried to_html()
and neither worked. To be clear: I think the output looks correct, but VS code is not rendering it. Perhaps this is a VSCode rendering issue?
sidenote: I received a VSCode notification today asking me to take a survey about what I liked and disliked about the Jupyter Notebook experience in VSCode. I took this opportunity to cite this bug report. :)
Comment From: attack68
closing this as pandas unrelated. Feel free to reopen if more info comes to light.