python - Plot a Data Set According to Counts of Categories of a Variable -


i have dataset has 14 columns (i had use 4 columns: travelling class, gender, age, , fare price) have split train , test data sets. need create vertical bar chart train data set distribution of passengers travelling class (1, 2, , 3 classes). not allowed use numpy, pandas, scipy, , scikit-learn.

i new python, , know how plot simple graphs, when comes more complicated graphs, bit lost.

this code (i know there lot wrong):

travelling_class = defaultdict(list) row in data:     travelling_class[row[0]]  travelling_class = {key: len(val) key, val in travelling_class.items()}  keys = travelling_class() vals = [travelling_class[key] key in keys] ind  = range(min(travelling_class.keys()), max(travelling_class.keys()) + 1) width = 0.6  plt.xticks([i + width/2 in ind], ind, ha='center') plt.xlabel('tracelling class')  plt.ylabel('counts of passengers') plt.title('number of passengers per travelling class') plt.ylim(0, 1000) plt.bar(keys, vals, width) plt.show() 

import matplotlib.pyplot plt  classes = travelling_class[1, 2, 3]  plt.hist(classes) plt.show() 

@trakjohnson original asker of question - sorry accidentally somehow deleted profile had make new one. thank help. problem data set 1045 rows, might difficult list of them. above seem reasonable?

use plt.hist, plot histogram (more info here)

example:

import matplotlib.pyplot plt  classes = [1, 2, 1, 1, 3, 3]  plt.hist(classes) plt.show() 

and result:

histogram


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -