Classwork 11

Pandas Fundamental II: Sorting, Indexing, and Locating Data

Author

Byeong-Hak Choe

Published

March 30, 2026

Modified

March 30, 2026

Direction

The nfl.csv file (with its pathname https://bcdanl.github.io/data/nfl.csv) contains a list of players in the National Football League with similar Name, Team, Position, Birthday, and Salary variables in the nba.csv file.

import pandas as pd 
import numpy as np

# Below is for an interactive display of DataFrame in Colab
from google.colab import data_table
data_table.enable_dataframe_formatter()

nfl = pd.read_csv(
    "https://bcdanl.github.io/data/nfl.csv",
    parse_dates=["Birthday"]
)




Question 1

  • Who are the five highest-paid players?
  • Who is the oldest player?

Answer:


Question 2

How can we sort the DataFrame first by Team in alphabetical order and then by Salary in descending order?

Answer:


Question 3

How can we find the five lowest-paid players using a method designed for finding extreme values?

Answer:


Question 4

How can we return all players whose salaries are tied among the four highest salaries?

Answer:


Question 5

Suppose you sorted nfl by Salary and assigned the result back to nfl. How could you restore the original row order?

Answer:


Question 6

How do we set the player names as the DataFrame index?

Answer:


Question 7

Create a new DataFrame called nfl2 with Name as the index. Then reset the index so that Name becomes a regular column again.

Answer:


Question 8

Who is the oldest player on the Kansas City Chiefs roster, and what is his birthday?

Answer:


Question 9

Using .loc, how can we extract the rows for Patrick Mahomes and Travis Kelce after setting Name as the index?

Answer:


Question 10

After setting Name as the index and sorting the index alphabetically, how can we extract all rows from Josh Allen through Lamar Jackson using .loc slicing?

Answer:


Question 11

Using .iloc, how can we extract: - the row in position 10; - the rows in positions 10 through 14?

Answer:


Question 12

After setting Name as the index, how can we use .loc to extract only the Team and Salary columns for Patrick Mahomes?

Answer:


Question 13

Using .iloc, how can we extract the first five rows and the first three columns only?

Answer:



Discussion

Welcome to our Classwork 11 Discussion Board! πŸ‘‹

This space is designed for you to engage with your classmates about the material covered in Classwork 11.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 11 materials or need clarification on any points, don’t hesitate to ask here.

All comments will be stored here.

Let’s collaborate and learn from each other!

Back to top