Skip to content

Commit add689b

Browse files
authored
corrected challenge format and added context
Updated to comply with Carpentries' format for challenges. Also added context by referring to original lesson `06-loops-and-functions.md` and adapting commands from it.
1 parent a837e0b commit add689b

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

_extras/extra_challenges.md

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,31 @@ permalink: /extra_challenges/
88

99
A collection of challenges that have been either removed from or not (yet) added to the main lesson.
1010

11-
## 06-loops-and-functions
12-
13-
### Looping Over Dataframe Challenges
14-
15-
* What happens if there is no data for a year in the sequence (for example, imagine we had used 1976 as the start year in `range`)
16-
~~~
17-
An empty file with only the headers
18-
~~~
19-
{: .output}
11+
> ## Looping Over Dataframe
12+
>
13+
> (Please refer to lesson `06-loops-and-functions.md`)
14+
>
15+
> The file `surveys.csv` in the `data` folder contains 25 years of data from surveys,
16+
> starting from 1977. We can load the data and print all the years surveyed using a `for` loop:
17+
>
18+
> ~~~
19+
> import pandas as pd
20+
>
21+
> # Load the data into a DataFrame
22+
> surveys_df = pd.read_csv('data/surveys.csv')
23+
>
24+
> # Loop through a sequence of years and print the year
25+
> start_year = 1977
26+
> end_year = 2002
27+
> for year in range(start_year, end_year+1):
28+
> print(str(year))
29+
> ~~~
30+
> {: .language-python}
31+
>
32+
> What happens if there is no data for a year in a sequence? For example,
33+
> imagine we used `1976` as the start year in `range`
34+
>
35+
> > ## Solution
36+
> > An empty file with only the headers
37+
> {: .solution}
38+
{: .challenge}

0 commit comments

Comments
 (0)