Skip to main content

A python library to load structured table data from files/strings/URL with various data format: CSV/Excel/Google-Sheets/HTML/JSON/LTSV/Markdown/SQLite/TSV.

Project description

pytablereader

https://badge.fury.io/py/pytablereader.svg https://img.shields.io/pypi/pyversions/pytablereader.svg Linux CI test status Windows CI test status https://coveralls.io/repos/github/thombashi/pytablereader/badge.svg?branch=master https://img.shields.io/github/stars/thombashi/pytablereader.svg?style=social&label=Star

Summary

A python library to load structured table data from files/strings/URL with various data format: CSV/Excel/Google-Sheets/HTML/JSON/LTSV/Markdown/SQLite/TSV.

Features

  • Extract structured tabular data from various data format:
  • Supported data sources are:
    • Files on a local file system

    • Accessible URLs

    • str instances

  • Loaded table data can be used as:

Examples

Load a CSV table

import pytablereader as ptr
import pytablewriter as ptw


# prepare data ---
file_path = "sample_data.csv"
csv_text = "\n".join([
    '"attr_a","attr_b","attr_c"',
    '1,4,"a"',
    '2,2.1,"bb"',
    '3,120.9,"ccc"',
])

with open(file_path, "w") as f:
    f.write(csv_text)

# load from a csv file ---
loader = ptr.CsvTableFileLoader(file_path)
for table_data in loader.load():
    print("\n".join([
        "load from file",
        "==============",
        "{:s}".format(ptw.dump_tabledata(table_data)),
    ]))

# load from a csv text ---
loader = ptr.CsvTableTextLoader(csv_text)
for table_data in loader.load():
    print("\n".join([
        "load from text",
        "==============",
        "{:s}".format(ptw.dump_tabledata(table_data)),
    ]))
load from file
==============
.. table:: sample_data

    ======  ======  ======
    attr_a  attr_b  attr_c
    ======  ======  ======
         1     4.0  a
         2     2.1  bb
         3   120.9  ccc
    ======  ======  ======

load from text
==============
.. table:: csv2

    ======  ======  ======
    attr_a  attr_b  attr_c
    ======  ======  ======
         1     4.0  a
         2     2.1  bb
         3   120.9  ccc
    ======  ======  ======

Get loaded table data as pandas.DataFrame instance

from pytablereader import TableData

TableData(
    table_name="sample",
    header_list=["a", "b"],
    record_list=[[1, 2], [3.3, 4.4]]
).as_dataframe()
     a    b
0    1    2
1  3.3  4.4

For more information

More examples are available at http://pytablereader.rtfd.io/en/latest/pages/examples/index.html

Installation

pip install pytablereader

Dependencies

Python 2.7+ or 3.3+

Mandatory Python packages

Optional Python packages

  • pypandoc
    • required when loading MediaWiki file

  • pandas
    • required to get table data as a pandas data frame

Optional packages (other than Python packages)

  • lxml (faster HTML convert if installed)

  • pandoc (required when loading MediaWiki file)

Test dependencies

Documentation

http://pytablereader.rtfd.io/

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytablereader-0.11.4.tar.gz (63.6 kB view hashes)

Uploaded Source

Built Distribution

pytablereader-0.11.4-py2.py3-none-any.whl (46.1 kB view hashes)

Uploaded Python 2 Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page