python-3.x - 如何摆脱 Python Pandas 中的斜体并获取纯文本?

标签 python-3.x pandas ipython jupyter-notebook

我在 Python 3 中将文本保存到 csv 文件。 文本很干净,没有任何标签。 这是它在记事本中的外观: enter image description here

这是我的文本灯泡:

  unicodedata.normalize('NFKD',' '.join(i[1:-1]) 
).encode('ascii','ignore').decode()

我是这样保存的:

def save(filename, data):
    with open(r"path to file\{}.csv".format(filename),"a",encoding="utf-8"  ) as f:
        w = csv.DictWriter(f, [coulm names],lineterminator="\n")
        w.writeheader()
        w.writerows(data[:10])

当我在 Ipython Pandas 作为 DataFrame 中打开文件时,我可以看到不同样式的文本,如下所示: enter image description here

如何摆脱它并使所有文本看起来都一样? 附言gsheets 中的一切看起来都很好: enter image description here PS。我在 pandas 中使用以下命令:

data_full = pd.read_csv("restaurant_menu_with_entryurl_full.csv", encoding = 'utf8')

PS。此外,如果我在 Pandas 中选择单列 View ,则文本看起来很统一。 enter image description here

最佳答案

我遇到了同样的问题。在深入研究之后,我发现 Pandas 上有一个选项可以禁用 MathJax。导入 pandas 后立即尝试执行此操作:

import pandas as pd
pd.set_option('display.html.use_mathjax', False)

关于 pandas 的更多显示选项的引用:https://pandas.pydata.org/pandas-docs/stable/user_guide/options.html

来自上面的链接:
“当为 True 时,Jupyter notebook 将使用 MathJax 处理表格内容,呈现由美元符号括起来的数学表达式。”

关于python-3.x - 如何摆脱 Python Pandas 中的斜体并获取纯文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52550355/

相关文章:

python - pandas:获取每隔一行的差异

python - 如何在 jupyter-notebook 中逐行执行代码?

python - 在 ipython qtconsole 中打印粗体、彩色等文本

python - 在 Matplotlib 中生成具有负轴和正轴的散点图

python - 如何使用 Pandas Groupby 和 nlargest

python - AttributeError : module object has no attribute "Series". 代码在 iPython 中有效

python - Python 中 if 语句流的逻辑

python 3 : Looking for alternatives to gevent and pylibmc/python-memcached

python - 使用python自动移动文件

python - 对于一个排序的numpy数组中的每个元素,如何减去另一个排序数组中的最小较大值