English 中文(简体)
在IPython笔记本中的“斑马表”?
原标题:"Zebra Tables" in IPython Notebook?

我在IPython建立一些互动工作流程,使用极好的交互式分析和熊猫笔记本。

I m 显示的表格中有些会比较容易阅读, 只需略加格式化即可 。 我非常喜欢“ 斑马 表格 ” 这样的表格, 其中每行都有阴影。 我 < a href=" http:// dev. opera.com/ articles/ view/ zebra- striping- tables- with- css3/" rel= “ nofollow noreferrer” >, 这里读到 < / a> 如何通过 css 执行格式。 是否有一条真正的直线前进路径将 css 应用到一个 < em> IPthon Notebook < / em > 上, 然后用样式表设置表格?

最佳回答

您可以在 标签内的标记单元格中,或者通过 IPython s IPython.core.display.Javascript 类运行任意的javascript(与 jQuery 一起) 。 有了这些, 您可以在您的心脏内容上操作( 或销毁) 文档, 包括添加样式表 。

例如,以下各段将适当分级表格:

<script type="text/javascript">
    $( head ).append(
        "<style type= text/css >tr.odd{background-color: #def}</style>"
    );
</script>

如果你把这个插进你的标记单元格, 那么它就会适用于页面上的所有内容。

或者,您可以在代码单元格中从 Python 运行相同的代码( minus < code_ lt; statiming> 标签) :

from IPython.core.display import Javascript, display
display(Javascript("""
    $( head ).append(
        "<style type= text/css >tr.odd{background-color: #def}</style>"
    );
"""))

但这样做只会影响你那些被适当分类的表格, 而这取决于正在写入 HTML 的代码(例如用熊猫) 。

问题回答

我刚刚发布了一个名为ipy_table的项目,为在IPython笔记本(颜色、边框、对齐、浮动格式、斑马阴影等)中创建内容丰富的格式化数据表格提供了一个简易的机制。该项目位于https://github.com/epmoy/ipy_table ,您可以从https://github.com/epmoy/ipy_table-reference.pdf/a>获得关于其能力的很好了解。

如果您对使用浮雕构建网格/表感兴趣, 但是在 python 中, 那么您也许对 qgrid 感兴趣 。 这是使用 padas 使用 ipython 笔记本的 ipython 笔记本 。

https://github.com/quantopian/qgrid" rel=“不跟随 nofollow noreferrerr>>https://github.com/quantopian/qgrid

另一个选项是使用像这样的可操作性 :

http://nbviewer.ipython.org/gist/bollwyvl/6ad2808844c60dda65

使用熊猫的第三个选择是:

Pandas Dataframes to_html:加亮表格列

第四个选项是使用像 Jinja2 这样的模板引擎 :

Pandas Dataframe 显示在网页

http://nbviewer.ipython.org/github/pydata/pandas/blob/8c4f9571c08d5122f1d9e40c43dadadab8b6f10ff5/pandas_HTML_styling.ipynb

最后,熊猫有一个有待根据模板解决的未决问题:

https://github.com/pydata/pandas/issues/3190

Google的P. S. Python Guru建议这一最起码的解决办法(避免任何第三方依赖):

https://stackoverflow.com/a/1475453/22308444

或读他的书:

Python in a Nutshell, 2nd Edition, Chapter 23 Structured Text: HTML





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签