values = ['y', 'n', '?'] vote_dtype = pandas.api.types.CategoricalDtype(categories=values) for c in votes.columns[1:]: votes[c] = votes[c].astype('object').astype( vote_dtype) democrats = votes[votes['class'] == 'democrat'] republicans = votes[votes['class'] == 'republican'] for vote_col in votes.columns[1:6]: pyplot.subplot(1, 2, 1) pyplot.hist([1 if x == 'y' else 0 for x in democrats[vote_col]]) pyplot.title('Democrats: n' + vote_col) pyplot.ylabel('count') pyplot.subplot(1, 2, 2) pyplot.hist([1 if x == 'y' else 0 for x in republicans[vote_col]]) pyplot.title('Republicans: n' + vote_col) pyplot.show()