Question: Please use clear handwriting and use Python. Thank you! The code below retrieves the data from the url. You should look at the url and
Please use clear handwriting and use Python. Thank you!

The code below retrieves the data from the url. You should look at the url and inspect the header to see how to retrieve horse power, origin, etc. Your task is to select all cars from origin "usa" with horsepower less than the average horse power. Implement the following strategy in Python: - Define a function that finds the average horse power of all cars. Use it to find the average horse power. - Define the following recursive function/strategy prob5. - prob5 is supposed to "selects all cars from origin usa with horse power less than average". - prob5 has 3 inputs: data, average horse power, and selected_data. - After prob5 is called, selected_data has all cars from usa with horse power less than average. - prob5 is defined recursively as follows: - If data is empty, there's nothing to select. - Otherwise, if the first item in the data satisfies the condition, append it to "selected_data". - Use the same strategy/function prob5 to select data from the remaining data. [9]: import pandas url = 'https: // raw.githubusercontent.com/mwaskom/seaborn-data /master/mpgcsv ' data = pandas. read_csv ( url ).values data [9] : array ([[18.0,8,307.0,,70, 'usa', 'chevrolet chevelle malibu'], [15.0,8,350.0,,70, 'usa', 'buick skylark 320'], [18.0,8,318.0,,70, 'usa', 'plymouth satellite'], [32.0,4,135.0,,82, 'usa', 'dodge rampage'], [28.0,4,120.0,,82, 'usa', 'ford ranger' ], [31.0,4,119.0,,82, 'usa', 'chevy s10]], dtype=object) 15]: def average_horse_power(data): pass # \# Note: after prob5 is called the list selected_data has all cars with horse power less than average. \# def prob5(data, average_hp, selected_data)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
