Anastasia
Anastasia

Reputation: 41

How to avoid markdown typesetting of $ signs in Jupyter output?

I am reading an Excel file in Jupyter, which contains income data, e.g. $2,500 to $4,999. Rendered output is returning:

the numbers

How can I avoid this formatting?

Upvotes: 4

Views: 3847

Answers (2)

David Hall
David Hall

Reputation: 535

In pandas>=0.23.0, you can prevent MathJax from rendering perceived LaTeX found in DataFrames. This is achieved using:

import pandas as pd

pd.options.display.html.use_mathjax = False

Upvotes: 5

jarmokivekas
jarmokivekas

Reputation: 187

In Jupyter you can use a backslash ( \ ) before the dollar sign to avoid starting a LaTeX math block.

So write \$2,500 in your markdown instead of $2,500.

A markdown cell like this:

Characterisic | Total with Income| \$1 to \$2,499 | \$2,500 to \$4,999
--------------|------------------|----------------|--------------
data          | data             |data            | data
data          | data             |data            | data

will be rendered by Jupyter like so: tabel renerd in jupyter notebook


If the table is handled with typical Jupyter tools (python,numpy,pandas) you can alter the column names with a short code snippet.

The snippet below will replace all $ strings in the column names with \$ so that Jupyter will render them without LaTeX math.

import pandas as pd
data = pd.read_excel("test.xlsx")
for col in range(0, len(data.columns.values)):
    data.columns.values[col] = data.columns.values[col].replace("$", "\$")
data

Before and after screenshot:

enter image description here

Upvotes: 1

Related Questions