我使用 python 包以表格格式将一些数据存储在文件中:tabulate
>>> print tabulate(table, headers, tablefmt="orgtbl")$
表格如下所示:
| name | num |
|--------+-------|
| abcd | 30 |
| efgh | 100 |
| ijklm | 10 |
现在我需要将这些数据提供给其他程序(用 python 编写)。 有没有简单的方法(我的意思是任何包)将表读入某些数据结构而不是显式解析它。换句话说,我可以将表格打印成其他格式(例如:网格、管道、媒体维基、 latex )是否有任何现成的解决方案可以将其从任何此类格式读入数据结构?
最佳答案
您可以看看astropy.io.ascii (以前称为 Asciitable )并查看它是否满足您的要求。
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
关于python - python中有没有从文件中读取表的包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34107914/