In-class Assignment: Installing Python Packages and Plotting with Maps in Python#

Day 4#

CMSE 202#

✅ Put your name here

#

✅ Put your group member names here

#

What if you wanted to make a map like the one below? How would you go about doing it using Python? Perhaps someone else already created a Python package that you could use!

Agenda for today’s class#

  1. Review

  2. Getting data from the web

  3. Practice with pip

  4. Visualizing data with maps

  5. Experimenting with generative AI


1. Review#

We’ll spend a bit of time going over anything that came up in the pre-class survey data.


2. Getting data from the web#

For this assignment we need to download a couple of data files. Here are direct links to the files:

https://raw.githubusercontent.com/wrobstory/vincent/master/examples/data/US_Unemployment_Oct2012.csv

https://raw.githubusercontent.com/python-visualization/folium/master/examples/data/us-states.json

Rather than navigating to them using your browser, downloading the file and then dragging it into the right location, let’s use your command line skills! Use the curl terminal command we revisited in the pre-class assignment instead.

Hint: Remember the trick we learned in a previous class period? You can actually run terminal commands from inside python. All you need to do is add the “!” to the beginning of your command.

✅ Do This: As a refresher, try it out – run the ls -la command by using the following python code:

!ls -la

✅ Do This: Now download the two data files we need for class using the curl command prefaced by the python terminal command (!). Important: you want to make sure that curl downloads and saves the file on to your computer, but by default it will just print the contents of the file to the screen. You should have figured out how to save it as a file in previous assignments, but don’t hesitate to ask a group member if it’s slipping your mind.

# Put your code here

✅ Do This: As a group inspect the two new files.

Question 1: What types of files are they? What type of data do they seem to contain? Be prepared to share your answers with your instructors and/or the class.

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Figure out how to load the US_Unemployment_Oct2012.csv into python and display some of the data. What libraries did you use?

#Put your code here. 

3. Practice with pip#

Lets switch gears and talk about installing software. Consider the following plotly package:

https://plot.ly/python/

Question 2 : What does this package do?

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Install the plotly package using pip and the python terminal operator (!) or inside your command line interface. You might run into issues as happens sometimes when install new packages. It might also take a bit of time for the package to install. If you run into issues, get help from your group mates to the instructors.

Important note: Did plot install as you expected? If not, why not? After trying to install plotly, what version is on your computer? Is it the latest version? What command could you use to check this? (hint: this command is included in the PCA) If you don’t have the latest version, how do you update it or install the specific version included on the “Getting Started” page?

#Put your code here

✅ Do This: Read through the documentation for running plotly and try to get an example to successfully run in your notebook. Make sure to help your group mates to get it working! You might find this page particular useful to take a look at: https://plotly.com/python/getting-started/

#Put your example code here

4. Visualizing data with maps#

Finding good ways to create map visualizations in Python can be tricky and there are quite a number of tools out there that can do it. This part of the assignment will provide you with an opportunity to find new packages and learn how to use them to accomplish this task.

Getting used to learning how to use new packages is an important part of becoming a Python expert!

✅ Do This: Debug the following example code. If you have to use any terminal commands to fix the bug make sure you include those here.

import folium
map_msu = folium.Map(location=[42.7284006,-84.4804778])
folium.Marker([42.7284006,-84.4804778], popup='MSU').add_to(map_msu)
map_msu

Question 3: What does the above example do?

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

Question 4: Assuming we did everything up to this point correctly, what does the following code do? Warning: there may be a bug in the code!

import folium
import pandas as pd

state_geo = r'./us-states.json'
state_unemployment = r'./US_Unemployment_Oct2012.csv'

state_data = pd.read_csv(state_unemployment)

#Let Folium determine the scale
employ_map = folium.Map(location=[48, -102], zoom_start=3)
folium.Choropleth(geo_path=state_geo, data=state_data,
             columns=['State', 'Unemployment'],
             key_on='feature.id',
             fill_color='YlOrRd', fill_opacity=0.7, line_opacity=0.2,
             legend_name='Unemployment Rate (%)', smooth_factor=0.1,highlight=True).add_to(employ_map)
folium.LayerControl().add_to(employ_map)

employ_map

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Modify the above code so that the state colors range from green to blue.

Question 5: What other colors are avaliable in the folium library? Is there a finite list of possible options?

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Explore some of the other function arguments that are available in the choropleth() and determine how they alter the map visualization. Make note of any argument that you find to be particularly interesting or useful. Or, alternatively, any settings that return a comical or useless version of the map.

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

Question 6: What controls in binning of values on the “Unemployment Rate” bar (upper right of the figure)? Can you set the bins manually? How would you do this? You might want to test it out with a bit of code or consult the folium documentation.

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Think about some other ways that having a package like folium could be useful. Try to find at least three examples on the web of scientific data being represented on a map. Include links to your examples below and explain what the data is trying to represent.

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

More than one way to make a map…#

Folium isn’t the only Python package out there that can plot data on a map. Spend some time finding other Python packages that can allow you to work with maps and data in Python. Some of the solutions you find might use modules you’re already familiar with, some of them might use new modules. Explore the options and choose one that you want to try to get working.

✅ Do This: In the cell below try to get at least one example working in your notebook using a package other than folium for plotting data on a map. Feel free to discuss any issues your run into with the rest of your group!


5. Introduction to HiTA (Your virtual course assistant)#

In this part of the assignment we’re going to introduce HiTA. For this course we setup a custom LLM that has been trained specifically on the content covered in this course. Since it is trained directly on the course content, its answers should be much more relevant to this course than using an online LLM such as ChatGPT, which does not limit its answers to concepts that you have learned and are familiar with. As well, the tool has been trained to act as a TA rather than an answer key, so it should better guide learning rather than replacing it like many other tools.

✅ Do This: As an introduction to HiTA, go into the HiTA tool for this course and complete the activity posted there.

What is your experience with using the tool? Does it produce results you expect? What are some of the limitations of the tool? What are some of the benefits?

Do This - Erase the contents of this cell and replace it with your answer to the above question! (double-click on this text to edit this cell, and hit shift+enter to save the text)

✅ Do This: Now that you’ve experimented with using this tool, see if you can accomplish the task posted at the end of Part 4 with guidance from the tool.

Important note: Don’t forget to include comments in your code or in a markdown cell citing that you used HiTA (or another tool) to help you write the code. You should also make sure to include the prompt you used to get to your final code.

Example citation: “HiTA.ai, Accessed: Sept. 8, 2025 {Prompt Chain: how do you properly cite usage of an AI tool?}

# Put your AI-assisted mapping code here
# Make sure to cite the tool you use and the key prompt you used to get to things working


Congratulations, we’re done!#

Now, you just need to submit this assignment by uploading it to the course Desire2Learn web page for today’s dropbox (Don’t forget to add your name in the first cell).