31 Years of Python | 48 Hour Sale Extension!!!

Introduction to Numpy Week 12 Task 2

Directions: Extract the 14th column in "taxi_first_five" . Assign to "fare_totals"

My Code:

fare_totals= taxi_first_five- taxi_first_five[14]

What actually happened:

IndexError: index 14 is out of bounds for axis 0 with size 5

The correct answer is fare_totals = taxi_first_five[:,13] but I don’t understand the logic of it. Can you please help me?

Hi alejandra.orcutt

The taxi_first_five variable has the first 5 rows only. Hence, if you check the variable you could see that taxi_first_five has 5 rows and 14 columns.
By taxi_first_five[14], you are trying to access the 13th row in taxi_first_five, which doesn’t exist. That’s why you are getting the IndexError.

This will assign all the rows in the 13th column of taxi_first_five, which is the total_amount column.

Is it clear now?

1 Like