Пример #1
0
def summary():
    '''
    summerize all the promising stock information
    '''
    summaries = []
    for s in st_list[:20]:
        summaries.append(get_information(s))
    text = tabulate(summaries, headers = 'keys', tablefmt='fancy_grid')
    print(text)
    table_html = tabulate(summaries, headers = 'keys', tablefmt='html')
    return table_html
Пример #2
0
def summary():
    '''
    summerize all the promising stock information
    '''
    summaries = []
    for s in st_list[:20]:
        summaries.append(get_information(s))
    text = tabulate(summaries, headers='keys', tablefmt='fancy_grid')
    print(text)
    table_html = tabulate(summaries, headers='keys', tablefmt='html')
    return table_html
Пример #3
0
 def dump_tabular(self, *args, **kwargs):
     wh = kwargs.pop("write_header", None)
     if len(self._tabular) > 0:
         for line in tabulate(self._tabular).split('\n'):
             self.log(line, *args, **kwargs)
         tabular_dict = dict(self._tabular)
         for tabular_fd in list(self._tabular_fds.values()):
             writer = csv.DictWriter(tabular_fd,
                                     fieldnames=list(tabular_dict.keys()))
             if wh or (wh is None
                       and tabular_fd not in self._tabular_header_written):
                 writer.writeheader()
                 self._tabular_header_written.add(tabular_fd)
             writer.writerow(tabular_dict)
             tabular_fd.flush()
         del self._tabular[:]
Пример #4
0
def tabulate(data, headr=(), formatters=(), inds='nice'):
    """Pre-processor for tabulate().
  data:  list-of-lists, whose 'rows' will be printed as columns.
         This coincides with the output of Dict.values().
  headr: list or tuple.
  If 'data' is a dict, then the keys will be the headr.
  formatter: define formats to apply before relaying to pandas.
        Default: attr.__name__ (when applicable).
  Example:
  >>> print(tabulate(cfgs.distinct_attrs()))
  """

    # Extract headr/mattr
    if hasattr(data, 'keys'):
        headr = list(data)
        data = data.values()

    # Default formats
    if not formatters:
        formatters = ({
            'test': lambda x: hasattr(x, '__name__'),
            'format': lambda x: x.__name__
        }, )
    # Apply formatting (if not applicable, data is just forwarded)
    for f in formatters:
        data = [[f['format'](j) for j in row] if f['test'](row[0]) else row
                for row in data]

    # Transpose
    data = list(map(list, zip(*data)))

    # Generate nice indices
    if inds == 'nice':
        inds = ['[{}]'.format(d) for d in range(len(data))]
    else:
        pass  # Should be True or False

    return tabulate_orig.tabulate(data, headr, showindex=inds)