def summarize_with_groups(dframe, stats, group): """ Calculate summary statistics for group. """ grouped_stats = series_to_jsondict( dframe.groupby(group).apply(summarize_df)) stats.update({group: grouped_stats}) return stats
def summarize_df(dframe): """ Calculate summary statistics """ dtypes = dframe.dtypes # TODO handle empty data # before we wrapped with filter(lambda d: d[DATA] and len(d[DATA]), array) return dict([ (col, { SUMMARY: series_to_jsondict(summarize_series(dtypes[col], data)) }) for col, data in dframe.iteritems() if not col in MONGO_RESERVED_KEYS ])