Skip to content

Commit 404c388

Browse files
authored
correct plotting a joined data frame exercise
1 parent 535175e commit 404c388

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

episodes/05-merging-data.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -149,24 +149,24 @@ new_output = pd.read_csv('data/out.csv', keep_default_na=False, na_values=[""])
149149

150150
### Challenge - Combine Data
151151

152-
In the data folder, there is another folder called `yearly_files`
153-
that contains survey data broken down into individual files by year.
154-
Read the data from two of these files,
155-
`surveys2001.csv` and `surveys2002.csv`,
152+
In the data folder, there are additional files
153+
that contain survey data broken down into individual files by year.
154+
Read the data from
155+
`surveys2001.csv` and `surveys2002.csv`
156156
into pandas and combine the files to make one new DataFrame.
157-
Create a plot of average plot weight by year grouped by sex.
157+
Create a plot of average weight by year grouped by sex.
158158
Export your results as a CSV and make sure it reads back into pandas properly.
159159

160160
::::::::::::::::::::::: solution
161161

162162
```python
163163
# read the files:
164-
survey2001 = pd.read_csv("data/yearly_files/surveys2001.csv")
165-
survey2002 = pd.read_csv("data/yearly_files/surveys2002.csv")
164+
survey2001 = pd.read_csv("data/surveys2001.csv")
165+
survey2002 = pd.read_csv("data/surveys2002.csv")
166166
# concatenate
167167
survey_all = pd.concat([survey2001, survey2002], axis=0)
168168
# get the weight for each year, grouped by sex:
169-
weight_year = survey_all.groupby(['year', 'sex']).mean()["wgt"].unstack()
169+
weight_year = survey_all.groupby(['year', 'sex']).mean()["weight"].unstack()
170170
# plot:
171171
weight_year.plot(kind="bar")
172172
plt.tight_layout() # tip: use this to improve the plot layout.

0 commit comments

Comments
 (0)