pandas/JupyterLab 将字符串的前半部分隐藏在 $$ 之间
pandas/JupyterLab hiding first half of string between $$
one two three
0 500_00 00_00 nan
1 500_00 00_00 7000
2 500_00 00_00 7000
3 500_00 00_00 7000
4 500_00 00_00 00_00
5 97500 77500 7000
6 7700 7000 7000
7 9000 7500 nan
8 9000 7500 7000
9 9500 7500 7000
当我在 Jupterlab 中显示这个 pandas 数据框时,它看起来像这样,在列之间的框中隐藏了值:
显然是两个 $
的括号导致了这种情况发生,但我无法在文档中的任何地方找到它。有人 运行 以前参与过这个吗?该功能的用途是什么?
破解
# Data preparing
>>> import pandas as pd
>>> from numpy import nan
>>> df = pd.DataFrame({'one': {0: '500_00',1: '500_00',2: '500_00',3: '500_00',4: '500_00',5: '97500',6: '7700',7: '9000',8: '9000',9: '9500'},'two': {0: '00_00',1: '00_00',2: '00_00',3: '00_00',4: '00_00',5: '77500',6: '7000',7: '7500',8: '7500',9: '7500'},'three': {0: nan,1: '7000',2: '7000',3: '7000',4: '00_00',5: '7000',6: '7000',7: nan,8: '7000',9: '7000'}})
# A hack
>>> df = df.apply(lambda x:x.str.replace("$", "$"))
>>> df
Pandas 有一个 display option display.html.use_mathjax
默认情况下是 True
:
When True, Jupyter notebook will process table contents using MathJax, rendering mathematical expressions enclosed by the dollar symbol.
您可以使用 pd.set_option('display.html.use_mathjax', False)
更改此设置。这将在 pandas.
中禁用自动 mathjax 样式
或者,您可以尝试更改样式。请参阅引用类似情况的此问题:https://github.com/pandas-dev/pandas/issues/40318
one two three
0 500_00 00_00 nan
1 500_00 00_00 7000
2 500_00 00_00 7000
3 500_00 00_00 7000
4 500_00 00_00 00_00
5 97500 77500 7000
6 7700 7000 7000
7 9000 7500 nan
8 9000 7500 7000
9 9500 7500 7000
当我在 Jupterlab 中显示这个 pandas 数据框时,它看起来像这样,在列之间的框中隐藏了值:
显然是两个 $
的括号导致了这种情况发生,但我无法在文档中的任何地方找到它。有人 运行 以前参与过这个吗?该功能的用途是什么?
破解
# Data preparing
>>> import pandas as pd
>>> from numpy import nan
>>> df = pd.DataFrame({'one': {0: '500_00',1: '500_00',2: '500_00',3: '500_00',4: '500_00',5: '97500',6: '7700',7: '9000',8: '9000',9: '9500'},'two': {0: '00_00',1: '00_00',2: '00_00',3: '00_00',4: '00_00',5: '77500',6: '7000',7: '7500',8: '7500',9: '7500'},'three': {0: nan,1: '7000',2: '7000',3: '7000',4: '00_00',5: '7000',6: '7000',7: nan,8: '7000',9: '7000'}})
# A hack
>>> df = df.apply(lambda x:x.str.replace("$", "$"))
>>> df
Pandas 有一个 display option display.html.use_mathjax
默认情况下是 True
:
When True, Jupyter notebook will process table contents using MathJax, rendering mathematical expressions enclosed by the dollar symbol.
您可以使用 pd.set_option('display.html.use_mathjax', False)
更改此设置。这将在 pandas.
或者,您可以尝试更改样式。请参阅引用类似情况的此问题:https://github.com/pandas-dev/pandas/issues/40318