From 477f71a6ec764ea6c7ed33f04f3d6fea9a14c580 Mon Sep 17 00:00:00 2001 From: Niru Maheswaranathan Date: Thu, 26 Feb 2015 12:29:55 -0800 Subject: [PATCH] added frame() helper function to print a pandas DataFrame --- setup.py | 4 ++-- tableprint.py | 29 ++++++++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index d950768..4e5370b 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.1.0', + version='0.1.1', description='Pretty ASCII printing of tabular data', long_description=long_description, @@ -65,7 +65,7 @@ setup( # project is installed. For an analysis of "install_requires" vs pip's # requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=[], + install_requires=['pandas'], # List additional groups of dependencies here (e.g. development dependencies). # You can install these using the following syntax, for example: diff --git a/tableprint.py b/tableprint.py index ded2d95..a860632 100644 --- a/tableprint.py +++ b/tableprint.py @@ -3,8 +3,35 @@ Module to nicely format ASCII table rows for display """ +# imports +import numpy as np + # exports -__all__ = ['table', 'row', 'header'] +__all__ = ['table', 'row', 'header', 'frame'] + + +def frame(df, options=None): + """ + Print an ASCII table using the given pandas DataFrame + + Parameters + ---------- + df : DataFrame + A pandas DataFrame with consisting of the table to print + + options : dict + A dictionary of options. Defaults: + { + 'column_width' : 10, # the width of each column in the table + 'outer_char' : '|', # the character defining the outer border of the table + 'corner_char' : '+', # printed at the junctions of the table lines + 'line_char' : '-', # character as part of each horizontal rule + 'precision' : '2f' # precision string for formatting numbers + } + + """ + + table(np.array(df), list(df.columns), options) def table(data, headers, options=None):