Python table instruction and installation

Source: Internet
Author: User

Python install pip

Visit our website:

Https://pypi.python.org/pypi/pip

Download:

https://pypi.python.org/packages/e7/a8/7556133689add8d1a54c0b14aeff0acb03c64707ce100ecd53934da1aa13/ pip-8.1.2.tar.gz#md5=87083c0b9867963b29f7aba3613e8f4a

Installation:

Tar fvxz pip-8.1.2.tar.gz && cd pip-8.1.2 && chmod +x setup.py && python setup.py installpip2.6 Install tabulate

Execute Python:

>>> from tabulate import tabulate success

Table for listing fields

>>> table = [["Sun", 696000,1989100000],["Earth", 6371,5973.6],["Moon", 1737,73.5],["Mars", 3390,641.85]] >>> Print tabulate (table)------------------------Sun 696000 1.9891e+09earth 6371 5973.6Moon 17 Panax 73.5Mars 3390 641.85------------------------

Second, put the corresponding field head to the front of the table

Using the Headers option

>>> Print tabulate (table, headers=["Planet", "Sina", "Baidu"]) Planet sina Baidu----------------- ----------Sun 696000 1.9891e+09earth 6371 5973.6Moon 1737 73.5Mars 3390 641.85

If the row header is in the first field, use headers= "FirstRow"

As follows:

>>> print tabulate ([["Name", "Age"],["Liyuanchuaun", "+"],["Gaolixu", "+"]],headers= "FirstRow") Name Age -----------------Liyuanchuaun 25gaolixu 25

Many of the formats supported by table are as follows:

Supported table formats is:

  • "Plain"

  • "Simple"

  • "Grid"

  • "Fancy_grid"

  • "Pipe"

  • "Orgtbl"

  • "RST"

  • "MediaWiki"

  • "HTML"

  • "Latex"

  • "Latex_booktabs"

In order to test each parameter, which parameter can be selected by itself

>>> table = [["spam", 42],["eggs", 455],["bacon", 23]]>>> headers =  ["Item", "Qty"]>>> print tabulate (table,headers) item       qty------  -----spam       42eggs       455bacon      23>>> print tabulate (Table,headers, Tablefmt= "plain") item      qtyspam        42eggs      455bacon      23>>>  Print tabulate (table,headers,tablefmt= "simple") item      qty------   -----Spam       42eggs      455bacon       23>>> print tabulate (table,headers,tablefmt= "grid")   +--------+-------+| item   |   qty |+========+=======+| spam   |     42 |+--------+-------+| eggs   |   455 |+------ --+-------+| bacon  |    23 |+--------+-------+>>> print  tabulate (table,headers,tablefmt= "psql") +--------+-------+| item   |    qty | | --------+-------||  spam   |    42 | |  eggs   |   455 | |  bacon  |    23 |+--------+-------+>>> print  Tabulate (table,headers,tablefmt= "rst")  ======  =====item      qty ======  =====spam       42eggs       455bacon      23======  =====>>> prInt tabulate (table,headers,tablefmt= "orgtbl") | item   |   qty | | --------+-------||  spam   |    42 | |  eggs   |   455 | |  bacon  |    23 |>>> print tabulate (Table,headers, tablefmt= "MediaWiki") {| class= "wikitable"  style= "text-align: left;" | + <!-- caption -->|-! item   !!  align= "Right" |   qty|-| spam   | |  align= "Right" |    42|-| eggs   | |  align= "Right" |   455|-| bacon  | |  align= "Right" |    23|} >>> print tabulate (table,headers,tablefmt= "HTML")      <table ><tr><th>item  </th><th style= "text-align: right;" >  qTy</th></tr><tr><td>spam  </td><td style= "text-align:  Right; " >   42</td></tr><tr><td>eggs  </td><td style = "text-align: right;" >  455</td></tr><tr><td>bacon </td><td style= " text-align: right; " >   23</td></tr></table>>>> print tabulate (table, headers,tablefmt= "Latex") \begin{tabular}{lr}\hline item   &   qty  \\hline spam   &    42 \ eggs   &    455 \ bacon  &    23 \\hline\end{tabular} >>>


This article is from the "Linux World" blog, so be sure to keep this source http://liyuanchuan8.blog.51cto.com/6060290/1845136

Python table instruction and installation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.