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:

Setup

  1. Create a new Python notebook inside your eds220-discussion-sections directory and rename it to section-3-snowshoe-hares.ipynb. Workbench or local are ok.

  2. Use the terminal to push this file to your remote repository.

General directions

  • Add comments as appropriate along your code.
  • Include markdown cells in between your code cells to add titles and information to each exercise.
  • Download the data file from the link in exercise 3. If you are working on workbench-1, upload the file to the server.
  • Indications about when to commit and push changes are included. Commit every time you finish a major step! Remember to write your commits in the imperative mood.

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

  1. 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.

  2. Use the dataset’s description and the metadata to answer the following questions:

    1. Who assembled this data, and why?
    2. What does a single row in the data represent?
    3. When and where were the observations collected?
    4. Does the dataset contain sensitive data?
    5. What study protocols were used to collect the data?
    6. What are the units for the hares’ weight?
    7. Does the metadata say how missing data is encoded?
    8. Is there a publication associated with this dataset?
  3. 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.

  4. 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:

  1. Go to this link.

  2. Get the URL of the hare image. To do this:

  • hover over the image –> right click –> “Copy Image Address”.
  1. At the end of the markdown cell with the dataset description, use markdown syntax to add the image from its URL:
![image description](URL-goes-here)
  1. 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

  1. Back in your notebook, import the 55_Hare_Data_2012.txt file available here. Store it in a variable named hares.

  2. Using pandas methods, 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

  1. 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.

  2. Get the number of times each unique sex non-NA value appears.

  3. Check the documentation of value_counts(). What is the purpose of the dropna parameter and what is its default value? Repeat step (b), this time adding the dropna=False parameter to value_counts().

  4. Discuss with your team the output of the unique value counts. In particular:

    1. Do the values in the sex column correspond to the values declared in the metadata?
    2. What could have been potential causes for multiple codes?
    3. Are there seemingly repeated values? If so, what could be the cause?
  5. Write code to confirm your suspicions about d-iii.

commit, pull, and push changes

5. Brainstorm

  1. Individually, write step-by-step instructions on how you would wrangle the hares data frame to clean the values in the sex column to have only two classes female and male. 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.

  2. 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

  1. Create a new column called sex_simple where:
  • F, f, and f_ (f with a space) in the sex column get assigned to ‘female’,
  • M, m, and m_ (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.

  1. Check the counts of unique values (including NAs) in the new sex_simple column.

commit, pull, and push changes

7. Calculate mean weight

  1. 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?

  2. Write a full sentence explaining the results you obtained. Don’t forget to include units.

  3. 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

Takeaway

Before you report a number, know what one row of your data represents and how your choices, like which codes to keep, shaped it!

References

[1]
K. Kielland, F. S. Chapin, R. W. Ruess, and Bonanza Creek LTER, “Snowshoe hare physical data in Bonanza Creek Experimental Forest: 1999-Present.” Environmental Data Initiative, 2017. doi: 10.6073/PASTA/03DCE4856D79B91557D8E6CE2CBCDC14. Available: https://portal.edirepository.org/nis/mapbrowse?packageid=knb-lter-bnz.55.22. [Accessed: Oct. 12, 2024]