Assignment 1¶
Part 1: Files, Git, GitHub¶
Use JupyterLab to launch a terminal and use the terminal to do the following tasks:
- Create a new directory called
resume
within your home directory - Create an empty file within this directory called
Readme.md
Now use JupyterLab to edit the file:
- Navigate to the directory in the file browser
- Open
Readme.md
in the text editor - Open
Readme.md
in in Markdown Preview - Arrange these files side-by-side so you can see your document rendered
Edit the file in the editor. Add the following information:
- Top level heading with your name
- An image. It can be a photo of you or, if you prefer, a photo of your spirit animal.
- Secondary heading entitled "Education"
- A list of schools you attended, hyperlinked to the websites of those insitutions
Save the file
Now go back to the terminal and do the following:
- Initialize a new git repository in the
resume
directory - Add the
Readme.md
file to the repository - Create a new commit with a commit message
- Check the git log to see your commit history
- Go to github and create a new public repository entitled
resume
- Push your local resume repository to GitHub following the instructions.
- View your online resume at
http://github.com/
/resume
Finally, go back to the editor and add a new subsection called "Research Interests" to your Readme.md
file. Update your local git repository and push your changes to GitHub. Verify that the remote repository is updated.
To "hand in" this part of the assignment, just provide the link to your repository in the notebook cell below.
Create your Assignments Repository¶
Now that you know how to create a git repository, you should create your assignments repository.
- Create a new directory called
rces-assignments
in your home directory. Copy the first assignment template into this directory (you will have to repeat this step each time a new assignment comes out.)
cp examples/content/Assignments/assignment_1.ipynb rces-assignments/
- Initialize a new git repository
- Add the file and make your first commit
- Create a new private repository on GitHub called
rces-assignments
. (Call it exactly like that. Do not vary the spelling, capitalization, or punctuation.) - Push your
rces-assignments
repository to github - On github, go to "settings" -> "collaborators" and add
rabernat
andxjin49
- Push new commits to this repository whenever you are ready to hand in your assignments
Part 2: Lists and Loops¶
In this problem, we will explore the basic data structures and flow controls of python by manually parsing a CSV file.
Note that this is a futile exercise. In the "real world" you should never manually parse a CSV file. There are utilities out there that will do it for you much more quickly and efficiently. However, it is a useful exercise for learning python.
First we need to download a data file to parse. We can do this from the terminal, OR we can use !
to run shell commands directly from the notebook. However you do it, you need to run these commands:
wget https://tinyurl.com/rces-roster
mv rces-roster rces-roster.csv
Before starting the python part, use the JupyterLab file browser to browse to this file. Click to open it. What do you see?
Now we will begin the process of reading the file with python
Open the file using the open
function¶
Specifically, run the command
file = open('rces-roster.csv')
Use the help
function to get the documentation for your new variable file
¶
This will produce a long list of methods you can use with file
.
Read the lines of the file into a variable called lines
¶
Hint: use the documentation above to find the method that sounds most likely to do what you want.
What type of object is lines
?
It should be a familiar type we learned about in class.
Display lines
at the end of a cell in order to see its contents¶
Use slicing to display the first three items of the list. And the last 3¶
Create a new list called data
that does not contain the header row¶
Now iterate through lines
and print
the item if it contains your uni¶
By now you have figured out what is in this data. Let's now transform it into a more useful format.
Write code to transform the data into a dictionary whose keys are UNIs and whose values are full names.¶
(You might need to review Python's string methods.)
Use this dictionary to look up your own name using your uni¶
Figure out who has the longest last name in the class¶