Lists, Dictionaries, and Pandas
concepts: version control, git, github, lists, dictionaries, Pandas
The basketball roster will be different this year; there will different roster from when this video was recorded.
Video Demonstrations:
(You may not need the first two videos if you are already comfortable with Git and GitHub.)
- 01: GitHub Setup
- 02: Git Clone Instructions
- 03: Setup VS Code
- 04: Code a simple list in roster.py
- 05: Confirm or setup Git User Name and Email
- 06: First commit with intentional error
- 07: Second commit with list changed to loop
- 08: Pandas Coding and Commits
Create a Repository on GitHub
You will need to create a repository on your GitHub account. (See the video if you do not know how to do this.)
Name it 560-A-07-pandas
Note: this was assignment 09 last semester. The videos from last semester will instruct you to set this up as 09. Set it up as assingment 07.
After you create the repository, git clone the repository to your computer. This is also demonstrated in the video.
Confirm that you have set up a git username and git email. To check for this, run the following command in terminal (Mac) or gitBash(PC):
git config --list
You will then see something similar to my output if you already have entered your user.name and user.email:
lawrencejones@Lawrences-MacBook-Pro ~ % git config --list
credential.helper=osxkeychain
init.defaultbranch=main
user.name=ljonesdesign
user.email=larry@ljonesdesign.com
filter.lfs.required=true
...
If you do not see your user.name= or user.email listed, then you will need to run the following commands one at time: (put in your user.name and user.email, not John Doe)
git config --global user.name "John Doe"
git config --global user.email johndoe@example.com
After you run these commands run git config --list
to confirm your email and username:
$ git config --list
user.name=John Doe
user.email=johndoe@example.com
color.status=auto
color.branch=auto
color.interactive=auto
color.diff=auto
...
UNC Basketball Roster 2023-24
We will work with the data from this web page:
https://goheels.com/sports/mens-basketball/roster
You will create 1 file for this assignment named roster.py
. Instead of duplicating files to show progress (as we did with the snake game) you will use git commits to track progress.
There are 14 players listed on this website.
For the purposes of this assignment we will not need to list out all fourteen; in the beginning you can work with just a few. For the final submission, choose at least 10 players to list out via a Pandas DataFrame. (I have only done 3 for the video demonstrations).
Step one: create the file and write a list program.
roster.py
Put the link to the roster webpage as a comment in the first line.
Write program to list out the last names only. This does not require Pandas.
- Choose any three players, last name only.
- Define the list as
roster
. - Create the list with the apropriate list syntax.
Print out the list using the print function.
This is your output, but with your players:
['Bacot', 'Davis', 'Cadeau']
Save the file and commit this as roster list
(I demonstrate this on the command line in the video demo.)
Step two: Modify the program to print out a for
loop
Use the same list as you used in the previous file. Print this list using a for loop print out a for loop for the last names only.
This is your sample code output(will use the same five players as the previous file.):
Bacot
Davis
Cadeau
Save the file and commit this as roster loop
See the 08: Pandas Coding and Commits for a demonstration of the remaining steps.
Step three: Import Pandas as pd and create a DataFrame data = pdDataFrame(roster)
and print(data)
.
This is your sample code output:
0
0 Bacot
1 Davis
2 Cadeau
Save the file and commit this as 0 header
Step four: Import Pandas as pd and create a DataFrame and print data.
This is your sample code output:
Last Name
0 Bacot
1 Davis
2 Cadeau
Save the file and commit this as Last Name header
Remaining steps are demonstrated in the 08: Pandas Coding and Commits video