为什么我的Jupyter Markdown中的表格没有显示出来?

huangapple go评论54阅读模式
英文:

Why is my table on Jupyter markdown not showing?

问题

我正在为一个关于数据分析的纳米学位在Jupyter Notebook上做笔记(是的,我知道我可以使用Microsoft Word等软件,但我更愿意更熟悉Jupyter)。

我试图在一个Markdown单元格中可视化这个表格,但是它并没有像应该的那样显示表格,而是显示了一个字符串。对齐方式并不重要。

|workclass       |age      |fnlwgt       |education-num|capital-gain|capital-loss|hours-per-week|
|----------------|---------|-------------|-------------|------------|------------|--------------|
|Federal-gov     |42.590625|185221.243750|10.973958    |833.232292  |112.268750  |41.379167     |
|Local-gov       |41.751075|188639.712852|11.042045    |880.202580  |109.854276  |40.982800     |
|Never-worked    |20.571429|225989.571429|7.428571     |0.000000    |0.000000    |28.428571     |
|Private         |36.797585|192764.114734|9.879714     |889.217792  |80.008724   |40.267096     |
|Self-emp-inc    |46.017025|175981.344086|11.137097    |4875.693548 |155.138889  |48.818100     |
|Self-emp-not-inc|44.969697|175608.641480|10.226289    |1886.061787 |116.631641  |44.421881     |
|State-gov       |39.436055|184136.613251|11.375963    |701.699538  |83.256549   |39.031587     |
|Without-pay     |47.785714|174267.500000|9.071429     |487.857143  |0.000000    |32.714286     |

当我点击"运行"时,它只显示如下内容:

workclass age fnlwgt education-num capital-gain capital-loss hours-per-week
Federal-gov 42.590625 185221.243750 10.973958 833.232292 112.268750 41.379167
Local-gov 41.751075 188639.712852 11.042045 880.202580 109.854276 40.982800
Never-worked 20.571429 225989.571429 7.428571 0.000000 0.000000 28.428571
Private 36.797585 192764.114734 9.879714 889.217792 80.008724 40.267096
Self-emp-inc 46.017025 175981.344086 11.137097 4875.693548 155.138889 48.818100
Self-emp-not-inc 44.969697 175608.641480 10.226289 1886.061787 116.631641 44.421881
State-gov 39.436055 184136.613251 11.375963 701.699538 83.256549 39.031587
Without-pay 47.785714 174267.500000 9.071429 487.857143 0.000000 32.714286
英文:

I'm taking notes for a nanodegree on Data Analysis on a Jupyter Notebook (yes, I know I could use Microsoft Word and etc but I'd rather get more used to Jupyter).

I'm trying to visualize this table in a markdown cell but instead of showing the table like it's supposed to I just get a string. The alignment is irrelevant.

|workclass       |age      |fnlwgt       |education-num|capital-gain|capital-loss|hours-per-week|
|----------------|---------|-------------|-------------|------------|------------|--------------|
|Federal-gov     |42.590625|185221.243750|10.973958    |833.232292  |112.268750  |41.379167     |
|Local-gov 	 |41.751075|188639.712852|11.042045    |880.202580  |109.854276  |40.982800     |
|Never-worked    |20.571429|225989.571429|7.428571     |0.000000    |0.000000 	 |28.428571     |
|Private 	 |36.797585|192764.114734|9.879714     |889.217792  |80.008724   |40.267096     |
|Self-emp-inc    |46.017025|175981.344086|11.137097    |4875.693548 |155.138889  |48.818100     |
|Self-emp-not-inc|44.969697|175608.641480|10.226289    |1886.061787 |116.631641  |44.421881     |
|State-gov 	 |39.436055|184136.613251|11.375963    |701.699538  |83.256549 	 |39.031587     |
|Without-pay 	 |47.785714|174267.500000|9.071429     |487.857143  |0.000000    |32.714286     |

When I hit 'Run' it just shows something like this:

> |workclass |age |fnlwgt |education-num|capital-gain|capital-loss|hours-per-week| |----------------|---------|-------------|-------------|------------|------------|--------------| |Federal-gov |42.590625|185221.243750|10.973958 |833.232292 |112.268750 |41.379167 | |Local-gov |41.751075|188639.712852|11.042045 |880.202580 |109.854276 |40.982800 | |Never-worked |20.571429|225989.571429|7.428571 |0.000000 |0.000000 |28.428571 | |Private |36.797585|192764.114734|9.879714 |889.217792 |80.008724 |40.267096 | |Self-emp-inc |46.017025|175981.344086|11.137097 |4875.693548 |155.138889 |48.818100 | |Self-emp-not-inc|44.969697|175608.641480|10.226289 |1886.061787 |116.631641 |44.421881 | |State-gov |39.436055|184136.613251|11.375963 |701.699538 |83.256549 |39.031587 | |Without-pay |47.785714|174267.500000|9.071429 |487.857143 |0.000000 |32.714286 |

答案1

得分: 0

在每个分隔符('|')之前和之后加上一个空格:

| workclass          | age       | fnlwgt          | education-num | capital-gain | capital-loss | hours-per-week |
|-------------------|-----------|----------------|---------------|--------------|--------------|----------------|
| Federal-gov        | 42.590625 | 185221.243750  | 10.973958     | 833.232292   | 112.268750   | 41.379167      |
| Local-gov          | 41.751075 | 188639.712852  | 11.042045     | 880.202580   | 109.854276   | 40.982800      |
| Never-worked       | 20.571429 | 225989.571429  | 7.428571      | 0.000000     | 0.000000     | 28.428571      |
| Private            | 36.797585 | 192764.114734  | 9.879714      | 889.217792   | 80.008724    | 40.267096      |
| Self-emp-inc       | 46.017025 | 175981.344086  | 11.137097     | 4875.693548  | 155.138889   | 48.818100      |
| Self-emp-not-inc   | 44.969697 | 175608.641480  | 10.226289     | 1886.061787  | 116.631641   | 44.421881      |
| State-gov          | 39.436055 | 184136.613251  | 11.375963     | 701.699538   | 83.256549    | 39.031587      |
| Without-pay        | 47.785714 | 174267.500000  | 9.071429      | 487.857143   | 0.000000     | 32.714286      |

注意,第一个'|'和workclass之间有一个空格。

英文:

Put a space before and after each separating pipe ('|'):

| workclass       | age      | fnlwgt       | education-num | capital-gain | capital-loss | hours-per-week |
|----------------|---------|-------------|-------------|------------|------------|--------------|
| Federal-gov     | 42.590625 | 185221.243750 | 10.973958    | 833.232292  | 112.268750  | 41.379167     |
| Local-gov   | 41.751075 | 188639.712852 | 11.042045    | 880.202580  | 109.854276  | 40.982800     |
| Never-worked    | 20.571429| 225989.571429 | 7.428571     | 0.000000    | 0.000000    | 28.428571     |
| Private     | 36.797585|192764.114734 | 9.879714     | 889.217792  | 80.008724   | 40.267096     |
| Self-emp-inc    | 46.017025 | 175981.344086 | 11.137097    | 4875.693548 | 155.138889  | 48.818100     |
| Self-emp-not-inc | 44.969697 | 175608.641480 | 10.226289    | 1886.061787 | 116.631641  | 44.421881     |
| State-gov   | 39.436055 | 184136.613251 | 11.375963    | 701.699538  | 83.256549   | 39.031587     |
| Without-pay     | 47.785714 | 174267.500000 | 9.071429     | 487.857143  | 0.000000    | 32.714286     |

Becomes

workclass age fnlwgt education-num capital-gain capital-loss hours-per-week
Federal-gov 42.590625 185221.243750 10.973958 833.232292 112.268750 41.379167
Local-gov 41.751075 188639.712852 11.042045 880.202580 109.854276 40.982800
Never-worked 20.571429 225989.571429 7.428571 0.000000 0.000000 28.428571
Private 36.797585 192764.114734 9.879714 889.217792 80.008724 40.267096
Self-emp-inc 46.017025 175981.344086 11.137097 4875.693548 155.138889 48.818100
Self-emp-not-inc 44.969697 175608.641480 10.226289 1886.061787 116.631641 44.421881
State-gov 39.436055 184136.613251 11.375963 701.699538 83.256549 39.031587
Without-pay 47.785714 174267.500000 9.071429 487.857143 0.000000 32.714286

Notice how there's a space between the first | and workclass.

huangapple
  • 本文由 发表于 2023年8月9日 04:22:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76862966.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定