Search code examples
pythontabular

Is there any package to read table from file in python


I've stored some data in a file in tabular format using the python package: tabulate

>>> print tabulate(table, headers, tablefmt="orgtbl")$

The table looks like:

| name   |   num |
|--------+-------|
| abcd   |    30 |
| efgh   |   100 |
| ijklm  |    10 |

Now I need to feed this data to some other program(written in python). Is there any easy way(I mean any package) to read the table into some data structure instead of parsing it explicitly. In other words I could have printed the table into some other format(e.g: grid, pipe, media-wiki, latex) is there any ready made solution to read it into a data structure from any of such formats?


Solution

  • You might take a look at astropy.io.ascii (previously known as Asciitable) and see if it does some of what you want.

    The following shows a few of the ASCII formats that are available, while the section on Supported formats contains the full list.

    • Basic: basic table with customizable delimiters and header configurations
    • Cds: CDS format table (also Vizier and ApJ machine readable tables)
    • Daophot: table from the IRAF DAOphot package
    • Ecsv: Enhanced CSV format
    • FixedWidth: table with fixed-width columns (see also Fixed-width Gallery)
    • Ipac: IPAC format table
    • HTML: HTML format table contained in a <table> tag
    • Latex: LaTeX table with datavalue in the tabular environment
    • Rdb: tab-separated values with an extra line after the column definition line
    • SExtractor: SExtractor format table