@@ -578,10 +578,11 @@ total_count.plot(kind='bar');
578578> need to be in individual columns. Here's a simple example with some data where
579579> 'a', 'b', and 'c' are the groups, and 'one' and 'two' are the subgroups.
580580>
581- > ```
581+ > ~~~
582582> d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
583583> pd.DataFrame(d)
584- > ```
584+ > ~~~
585+ > {: .language-python }
585586>
586587> shows the following data
587588>
@@ -595,11 +596,12 @@ total_count.plot(kind='bar');
595596>
596597> We can plot the above with
597598>
598- > ```
599+ > ~~~
599600> # Plot stacked data so columns 'one' and 'two' are stacked
600601> my_df = pd.DataFrame(d)
601602> my_df.plot(kind='bar',stacked=True,title="The title of my graph")
602- > ```
603+ > ~~~
604+ > {: .language-python }
603605>
604606> 
605607>
@@ -618,7 +620,8 @@ total_count.plot(kind='bar');
618620>> ```python
619621>> by_site_sex = surveys_df.groupby(['plot_id','sex'])
620622>> site_sex_count = by_site_sex['weight'].sum()
621- >> ```
623+ >> ~~~
624+ >> {: .language-python }
622625>>
623626>> This calculates the sums of weights for each sex within each site as a table
624627>>
@@ -642,7 +645,8 @@ total_count.plot(kind='bar');
642645>> by_site_sex = surveys_df.groupby(['plot_id','sex'])
643646>> site_sex_count = by_site_sex['weight'].sum()
644647>> site_sex_count.unstack()
645- >> ```
648+ >> ~~~
649+ >> {: .language-python }
646650>>
647651>> The `unstack` method above will display the following output:
648652>>
@@ -667,7 +671,8 @@ total_count.plot(kind='bar');
667671>> s_plot = spc.plot(kind='bar',stacked=True,title="Total weight by site and sex")
668672>> s_plot.set_ylabel("Weight")
669673>> s_plot.set_xlabel("Plot")
670- >> ```
674+ >> ~~~
675+ >> {: .language-python }
671676>>
672677>> 
673678> {: .solution}
0 commit comments