SD 212 Spring 2023 / Homeworks


This is the archived website of SD 212 from the Spring 2023 semester. Feel free to browse around; you may also find more recent offerings at my teaching page.

hw05: Weak and stupid superheroes

  • Due before the beginning of class on Friday, January 20

For this homework, you will do a simple data processing task in two ways: using python and pandas, and using bash (command-line).

The data

It’s the superheroes dataset we saw in the intro unit. Follow that link to download it, or run the following on the command line:

wget "http://roche.work/courses/s23sd212/hw/bash/heroes.csv"

Important: Notice that this is actually a semicolon-separated values file. In python, you will have to tell pandas to use semicolon as the csv delimiter instead of a comma. And in bash, when you pass a semicolon as a command-line option, be sure to enclose it in quotes like ";" so it’s not interpreted by the shell but sent to the command instead.

Bash scripts

If you put one or more bash commands in a file called myprogram.sh, you can ask bash to execute all those commands as a script. For example, if the file myprogram.sh contains two lines:

cd
ls sd212/*.py

Then running bash myprogram.sh would first change to the home directory, then list all python programs in the sd212 directory.

Your task

Print out the names of the “bad heroes”, which are those who have a strength of 10 and an intelligence of low. For the given csv file, there should be 5 names:

Agent Bob
Wyatt Wingfoot
Stormtrooper
Jar Jar Binks
Ben 10

In python using pandas

Write a program badhero.py which reads a file called heroes.csv and prints the names of the bad superheros.

You should use the built-in functionality of pandas and try to avoid writing your own loops.

In bash

Write a bash script badhero.sh which contains linux commands to solve the same problem, printing out the names of weak, stupid superheros from heroes.csv.

We have learned about the bash commands cut and grep, as well as how to redirect output to files. You should be able to do this with just a few commands! If you need to make a temporary file like temp.csv, that’s okay.

Submit command

To submit files for this homework, run one of these commands:

submit -c=sd212 -p=hw05 badhero.py badhero.sh
club -csd212 -phw05 badhero.py badhero.sh