简体   繁体   English

在Pandas数据框中按数学符号命名列

[英]Naming columns by mathematical symbols in pandas dataframe

I want to add the units of my parameters next to each parameter as the name of a column in my dataframe. 我想将参数的单位添加到每个参数旁边,作为数据框中列的名称。 I also need to use statistical symbols for some column names such as μ and σ2. 对于某些列名,例如μ和σ2,我还需要使用统计符号。

I tried following code according to mathematical symbols in python that is r"$...$ but it does not work for dataframe: 我根据python中的数学符号尝试了以下代码,即r“ $ ... $,但不适用于数据框:

P[r"Infiltration rate ($1/\h^-1$)"]=r['ACH_Base']

in order to give (1/h^-1) unit to Infiltration rate parameter. 为了将(1 / h ^ -1)单位设为渗透率参数。 In my code I have already created a new dataframe "P" and I am adding the ACH_Base column in "r" dataframe to P. How can I add mathematical symbols for naming the columns in dataframes? 在我的代码中,我已经创建了一个新的数据框“ P”,并将“ r”数据框中的ACH_Base列添加到P中。如何添加数学符号来命名数据框中的列? Thanks!! 谢谢!!

It should work, but it depends on the backend used to display the dataframe. 它应该工作,但是取决于用于显示数据框的后端。 For instance, matplotlib has support to render LaTeX in plots. 例如,matplotlib支持在绘图中渲染LaTeX。 Here is an example: 这是一个例子:

https://matplotlib.org/users/usetex.html#text-rendering-with-latex https://matplotlib.org/users/usetex.html#text-rendering-with-latex

LaTeX can also be rendered in jupyter notebooks, but this does not apply to Python code, only for markdown cells: 乳胶也可以在jupyter笔记本电脑渲染,但这并不适用于Python代码,只为降价细胞:

http://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html?highlight=latex#LaTeX-equations http://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Working%20With%20Markdown%20Cells.html?highlight=latex#LaTeX-equations

"\\h" is an unknown symbol. “ \\ h”是未知符号。 Does P[r"Infiltration rate ($1/h^-1$)"]=r['ACH_Base'] work to display what you want? P[r"Infiltration rate ($1/h^-1$)"]=r['ACH_Base']可以显示您想要的内容?

What unit do you wish to display? 您要显示什么单位? You can refer to https://matplotlib.org/users/mathtext.html and https://matplotlib.org/users/usetex.html#usetex-tutorial for more information on how to render text with LaTex. 您可以参考https://matplotlib.org/users/mathtext.htmlhttps://matplotlib.org/users/usetex.html#usetex-tutorial以获得有关如何使用LaTex渲染文本的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM