如何在Markdown单元格Jupyter Notebook的左侧显示表格

问题描述

在2个代码单元之间的Markdown单元中有一个表格,它是自动居中的,我希望像文本一样位于该单元的左侧。

table is aligning in center of cell,want it to be on the left

这是代码

Let's use the first row of `indices` to classify the 0th flower in `X_test`.

species    | target
---        | ---
setosa     | 0
versicolor | 1
virginica  | 2

This cell prints the neighbor's position of closeness,index of the neighbor and that neighbor's `target` (Iris species).

解决方法

您可以使用Markdowndisplay来获得这样的结果。步骤如下:

from IPython.core.display import Markdown
m0 = Markdown('''
Let's use the first row of `indices` to classify the 0th flower in `X_test`.
''')
m1 = Markdown('''
|species    | target | 
|-----------|:------:|
|setosa     | 0      |
|versicolor | 1      |
|virginica  | 2      |
''')
m2 = Markdown('''
This cell prints the neighbor's position of closeness,index of the neighbor and that neighbor's `target` (Iris species).
''')

要显示,请执行

display(m0,m1,m2)