added frame() helper function to print a pandas DataFrame

This commit is contained in:
Niru Maheswaranathan
2015-02-26 12:29:55 -08:00
parent c6f5dbe4f3
commit 477f71a6ec
2 changed files with 30 additions and 3 deletions

View File

@@ -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):