Last active
October 23, 2019 18:10
-
-
Save stfuchs/a43b6c90e481b81b0739cccfda971243 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
def histogram(values, bins=100, xmin=None, xmax=None, xstr=lambda x: '%s' % x, linewidth=120, symbol='B0'): | |
sym = { | |
'B1': u'\u2591', # Light shade | |
'B2': u'\u2592', # Medium shade | |
'B3': u'\u2593', # Dark shade | |
'B4': u'\u2588', # Full Block | |
'B0': u'\u25a0'} # Black square | |
x = pd.Series(values) | |
xmin = xmin or x.min() | |
xmax = xmax or x.max() | |
counts = x[(x >= xmin) & (x <= xmax)].value_counts(sort=False, bins=bins) | |
strings = [(xstr(bucket.mid), count) for bucket, count in counts.iteritems()] | |
max_string = max(map(lambda x: len(x[0]), strings)) | |
scale = (linewidth - 11. - max_string) / counts.max() | |
print("# NumSamples = %d; Min = %s; Max = %s" % (len(values), xstr(xmin), xstr(xmax))) | |
for name, count in strings: | |
print('%s [%6d]: %s' % (name.ljust(max_string), count, sym.get(symbol, symbol) * int(count * scale))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment