带有美元符号的 pandas 列/索引值 [英] Pandas Column/Index Values With Dollar Signs
问题描述
给出以下数据框:
import pandas as pd
df=pd.DataFrame({'A':['$0-$20','$20+']})
df
A
0 0−20
1 $20+
如何获得最初指定的带有美元符号的第一个值(0-20)?它实际上以奇怪的字体显示零,我不确定为什么它适用于"$ 20 +"而不适用于"$ 0-" $ 20.
How can I get the first value (0-20) to display with the dollar signs, as I originally specified? It actually displays the zero in a strange font and I'm not sure why it works for "$20+" but not "$0-"$20".
我尝试过:
df=pd.DataFrame({'A':[str('$0-$20'),'$20+']})
...但没有骰子.
这就是我得到的:
我正在使用Jupyter笔记本(Anaconda 3,Python 3.5) 预先感谢!
I'm using the Jupyter notebook (Anaconda 3, Python 3.5) Thanks in advance!
推荐答案
在Jupyter中,$0-$
被解释为带标签的乳胶.看来您正在iPython中运行,并且可能正在发生类似的事情.
In Jupyter, the $0-$
gets interpreted as tagged latex. It looks like you are running in iPython and something similar is probably happening.
请注意0 -
上的奇数字体和-
之后的小节.我知道此栏是mathjax/chrome错误的产物,这是给我的提示.
Notice the odd font on the 0 -
and the bar after the -
. I know this bar is an artifact of a mathjax/chrome bug, which is what tipped me off.
您的数据框是完整的.显示出来是个问题.
You're dataframe is intact. It's displaying it that's an issue.
做这样的事情应该会有所帮助:
Doing something like this should help:
import pandas as pd
df=pd.DataFrame({'A':['$0-$20','$20+']})
print df.__repr__()
A
0 $0-$20
1 $20+
__repr__
方法体现了如何显示对象并返回字符串. Jupyter笔记本会改为调用_repr_html_
并将其通过HTML处理程序传递.
The __repr__
method embodies how an object is to be displayed and returns a string. Jupyter-notebook calls _repr_html_
instead and passes it through an HTML handler.
这篇关于带有美元符号的 pandas 列/索引值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!