首页 > 代码库 > Project 1 Program and Analysis

Project 1 Program and Analysis

 

  recent_grads["ShareMen"] = recent_grads["Men"]/recent_grads["Total"] # Create a new column named "ShareMen" , the value is column ‘Men‘ dedide "Total"
 

  Arts_column = pd.DataFrame(recent_grads[recent_grads["Major_category"]=="Arts"]) # Create a new DataFrame named Art_column, and the value is all the data with the Major named "Arts"

  Arts_fig = plt.figure(figsize=(8,8)) # Create a figure with 8*8 inch

  Arts_plot = Arts_fig.add_subplot(1,1,1) # Create a plot

  locs = np.arange(len(Arts_column["Major"])) #Return evenly spaced values within a given interval, the interval is the length of Arts_column["Major"]

  offset_locs = locs + 0.35 

  Arts_plot.set_xticks(offset_locs) 

  Arts_plot.set_xticklabels(Arts_column["Major"].tolist(),rotation = 90)

  bar_1 = Arts_plot.bar(locs,Arts_column["ShareMen"].tolist(),0.35) #plot.bar(Bar location, Bar value, bar width)

  bar_2 = Arts_plot.bar(offset_locs,Arts_column["ShareWomen"].tolist(),0.35,color = "green")

  plt.legend((bar_1,bar_2),("ShareMen","ShareWomen"),loc = "upper left")

  Arts_plot.grid(b="on",which = "major",axis = "both")

Project 1 Program and Analysis