Screen Link:
My Code:
trip_mph = taxi[:,7] / (taxi[:,8] / 3600)
speed_bool = trip_mph < 100
cleaned_taxi = []
cleaned_taxi.append(taxi[speed_bool])
mean_distance = cleaned_taxi[:,7].mean()
What I expected to happen:
The code should execute and give me the mean value of distance from cleaned_taxi list. The answer code worked well and is attached in the “other details” below. The only difference from my code than the answer code is that I created a new empty list and then appended it with cleaned data, but the answer code directly inputs the cleaned data into cleaned_taxi without creating one empty list.
What actually happened:
So in order to get a clean table with filtered data, I created an empty list called [cleaned_taxi] and appended it with the filltered [taxi] list. When I try to calculate distance’s mean value from cleaned_taxi list, an error message saying “list indices must be integers, not tuple” for my last line of code.
Answer code:
trip_mph = taxi[:,7] / (taxi[:,8] / 3600)
cleaned_taxi = taxi[trip_mph < 100]
mean_distance = cleaned_taxi[:,7].mean()
mean_length = cleaned_taxi[:,8].mean()
mean_total_amount = cleaned_taxi[:,13].mean()