Snowshoe hares at Bonanza Creek Experimental Forest
Week 3 - Discussion section
This discussion section will guide you through exploring data about snowshoe hares (Lepus americanus) in the Bonanza Creek Experimental Forest located in Alaska, USA. In this discussion section, you will:
- Practice markdown syntax for creating tables and inserting images
- Practice detecting and cleaning messy data
- Use
groupby()to calculate summary statistics by groups - Select, clean, and comment your code to create a condensed data analysis workflow
Setup
General directions
About the data
For these exercises we will use data about Snowshoe hares (Lepus americanus) in the Bonanza Creek Experimental Forest [1].
This dataset is stored in the Environmental Data Initiative (EDI) data repository. This is a huge data repository committed to making data Findable, Accessible, Interoperable, and Reusable (FAIR). It is the main repository for all the data associated with the Long Term Ecological Research Network (LTER).
The file you will use is a copy of 55_Hare_Data_2012.txt from version 22 of this EDI data package, downloaded in December 2025. When you cite the data, cite the EDI data package, not the course folder.
1. Archive exploration
Take some time to look through the dataset’s description in EDI and click around. Then click on View Full Metadata, go to the “Detailed Metadata” section and click on “Data Entities” to look at the descriptions for the dataset’s columns.
Use the dataset’s description and the metadata to answer the following questions:
- Who assembled this data, and why?
- What does a single row in the data represent?
- When and where were the observations collected?
- Does the dataset contain sensitive data?
- What study protocols were used to collect the data?
- What are the units for the hares’ weight?
- Does the metadata say how missing data is encoded?
- Is there a publication associated with this dataset?
In your notebook: use a markdown cell to briefly answer these questions. Include as well a citation, date of access, and a link to the archive.
Before you look at the data itself, think about what you learned about how this data was collected. In a markdown cell, write down two or three questions about possible issues you might find in the data.
Do not skip the archive exploration! Understanding your data provenance is a crucial part of the analysis
2. Adding an image
Back in your notebook, follow these steps to add an image of a hare using a URL:
Go to this link.
Get the URL of the hare image. To do this:
- hover over the image –> right click –> “Copy Image Address”.
- At the end of the markdown cell with the dataset description, use markdown syntax to add the image from its URL:
- Do you need to add an attribution in the image description? Check the license at the bottom of the Wikimedia page.
commit, pull, and push changes
3. Data loading and preliminary exploration
Back in your notebook, import the
55_Hare_Data_2012.txtfile available here. Store it in a variable namedhares.Using
pandasmethods, obtain preliminary information and explore this data frame. Consider answering some of these questions:
- What are the dimensions of the data frame and what are the data types of the columns? Do the data types match what you would expect from each column?
- Are there any columns that have a significant number of NA values?
- What are the minimum and maximum values for the weight and hind feet measurements?
- What are the unique values for some of the categorical columns?
- Did any of the issues you anticipated in 1c show up?
CHECK IN WITH YOUR TEAM
MAKE SURE YOU’VE ALL SUCCESSFULLY ACCESSED THE DATA BEFORE CONTINUING
commit, pull, and push changes
4. Detecting messy values
In the metadata section of the EDI repository, find the allowed values for the hares’ sex. Create a small table in a markdown cell showing the values and their definitions.
Get the number of times each unique sex non-NA value appears.
Check the documentation of
value_counts(). What is the purpose of thedropnaparameter and what is its default value? Repeat step (b), this time adding thedropna=Falseparameter tovalue_counts().Discuss with your team the output of the unique value counts. In particular:
- Do the values in the
sexcolumn correspond to the values declared in the metadata? - What could have been potential causes for multiple codes?
- Are there seemingly repeated values? If so, what could be the cause?
- Do the values in the
Write code to confirm your suspicions about d-iii.
commit, pull, and push changes
5. Brainstorm
Individually, write step-by-step instructions on how you would wrangle the
haresdata frame to clean the values in thesexcolumn to have only two classesfemaleandmale. Which codes would you assign to each new class? Remember: It’s ok if you don’t know how to code each step - it’s more important to have an idea of what you would like to do.Discuss your step-by-step instructions with your team.
The next exercise asks you to clean the sex codes. There are many ways of doing this. Use the approach you came up with in your brainstorm, or try a different one!
6. Clean values
- Create a new column called
sex_simplewhere:
F,f, andf_(f with a space) in thesexcolumn get assigned to ‘female’,M,m, andm_(m with a space) get assigned to ‘male’, and- missing values stay
NaN.
You decide what to do with the other codes (?, F?, f?, M?, m?, pf). In a markdown cell, write your choice and why you made it.
- Check the counts of unique values (including NAs) in the new
sex_simplecolumn.
commit, pull, and push changes
7. Calculate mean weight
Use
groupby()to calculate the mean weight by sex using the new column. Compare your result with a team who handled the other codes differently. Did your choice change the result?Write a full sentence explaining the results you obtained. Don’t forget to include units.
A news brief says: “Female snowshoe hares at Bonanza Creek are heavier than males.” With your team, list a few reasons why the data might not support this claim. Think about how the data was collected. Then pick one reason and write code to check it.
commit, pull, and push changes
8. Collect your code and explain your results
In a new code cell, collect all the relevant code to create a streamlined workflow to obtain the final result from exercise 7 starting from importing the data. Your code cell should:
- Only print the final results for mean weight by
sex_simple. - Not include output from intermediate variables or checks.
- Not include methods or functions that do not directly contribute to the analysis (even if they don’t print anything ex:
df.head()). - If appropriate, combine methods using method chaining instead of creating intermediate variables.
- Comment your code following our class comments guidelines.
- Use appropriate line breaks and indentation to make code readable.
commit, pull, and push changes