Skip to content

Commit 9c2a8b4

Browse files
tmorrellmaxim-belkin
authored andcommitted
full reformatting of code blocks
1 parent a2742ef commit 9c2a8b4

6 files changed

Lines changed: 40 additions & 25 deletions

_episodes/02-starting-with-data.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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
> ![Stacked Bar Plot](../fig/stackedBar1.png)
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
>> ![Stacked Bar Plot](../fig/stackedBar.png)
673678
> {: .solution}

_episodes/03-index-slice-subset.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,23 +122,26 @@ a = [1, 2, 3, 4, 5]
122122
>
123123
> 1. What value does the code below return?
124124
>
125-
> ```python
125+
> ~~~
126126
> a[0]
127-
> ```
127+
> ~~~
128+
> {: .language-python }
128129
>
129130
> 2. How about this:
130131
>
131-
> ```python
132+
> ~~~
132133
> a[5]
133-
> ```
134+
> ~~~
135+
> {: .language-python }
134136
>
135137
> 3. In the example above, calling `a[5]` returns an error. Why is that?
136138
>
137139
> 4. What about?
138140
>
139-
> ```python
141+
> ~~~
140142
> a[len(a)]
141-
> ```
143+
> ~~~
144+
> {: .language-python }
142145
{: .challenge}
143146
144147
@@ -230,14 +233,16 @@ the other will see the same changes to the reference object.
230233
231234
- **Copy** uses the dataframe's `copy()` method
232235
233-
```python
236+
~~~
234237
true_copy_surveys_df = surveys_df.copy()
235-
```
238+
~~~
239+
{: .language-python }
236240
- A **Reference** is created using the `=` operator
237241
238-
```python
242+
~~~
239243
ref_surveys_df = surveys_df
240-
```
244+
~~~
245+
{: .language-python }
241246
242247
Okay, that's enough of that. Let's create a brand new clean dataframe from
243248
the original data CSV file.
@@ -410,9 +415,10 @@ Experiment with selecting various subsets of the "surveys" data.
410415
> 2. You can use the `isin` command in Python to query a DataFrame based upon a
411416
> list of values as follows:
412417
>
413-
> ```python
418+
> ~~~
414419
> surveys_df[surveys_df['species_id'].isin([listGoesHere])]
415-
> ```
420+
> ~~~
421+
> {: .language-python }
416422
>
417423
> Use the `isin` function to find all plots that contain particular species
418424
> in the "surveys" DataFrame. How many records contain these values?

_episodes/04-data-types-and-format.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ surveys_df.dtypes
125125

126126
which **returns**:
127127

128-
```
128+
~~~
129129
record_id int64
130130
month int64
131131
day int64
@@ -136,7 +136,8 @@ sex object
136136
hindfoot_length float64
137137
weight float64
138138
dtype: object
139-
```
139+
~~~
140+
{: .language-python }
140141

141142
Note that most of the columns in our Survey data are of type `int64`. This means
142143
that they are 64 bit integers. But the weight column is a floating point value
@@ -222,7 +223,7 @@ surveys_df['record_id'].dtype
222223
223224
What happened in the last challenge activity? Notice that this throws a value error:
224225
`ValueError: Cannot convert NA to integer`. If we look at the `weight` column in the surveys
225-
data we notice that there are NaN (**N**ot **a** **N**umber) values. *NaN* values are undefined
226+
data we notice that there are NaN (**N**ot **a** **N**umber) values. **NaN** values are undefined
226227
values that cannot be represented mathematically. Pandas, for example, will read
227228
an empty cell in a CSV or Excel sheet as a NaN. NaNs have some desirable properties: if we
228229
were to average the `weight` column without replacing our NaNs, Python would know to skip

_episodes/06-loops-and-functions.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -623,13 +623,14 @@ values to the function using these keywords:
623623
> doesn't. Add some code to your function that writes out the CSV files, to check
624624
> for a directory to write to.
625625
>
626-
> ```Python
626+
> ~~~
627627
> if 'dir_name_here' in os.listdir('.'):
628628
> print('Processed directory exists')
629629
> else:
630630
> os.mkdir('dir_name_here')
631631
> print('Processed directory created')
632-
> ```
632+
> ~~~
633+
> {: .language-python }
633634
>
634635
> 4. The code that you have written so far to loop through the years is good,
635636
> however it is not necessarily reproducible with different datasets.

_episodes/07-visualization-ggplot-python.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ To build a `plotnine` graphic we need to:
7272
As we have not defined anything else, just an empty figure is available and
7373
presented.
7474

75+
As we have not defined anything else, just an empty figure is available and
76+
presented.
7577

7678
- Define aesthetics (`aes`), by **selecting variables** used in the plot and
7779
`mapping` them to a presentation such as plotting size, shape color, etc. You

_episodes/08-putting-it-all-together.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ figure number inside the parentheses:
256256
{: .language-python}
257257

258258
A single figure can also include multiple plots in a grid pattern. The
259-
`subplot()` command especifies the number of rows, the number of columns, and
259+
`subplot()` command specifies the number of rows, the number of columns, and
260260
the number of the space in the grid that particular plot is occupying:
261261

262262
~~~

0 commit comments

Comments
 (0)