question archive This is an exercise to write a Python program on Data Analysis using Pandas
Subject:Computer SciencePrice: Bought3
This is an exercise to write a Python program on Data Analysis using Pandas. Please download the data file automobile_data.csv from Moodle, and develop a Python program that performs the following tasks: 1. Create a Pandas DataFrame by loading the file automobile_data.csv, using the "index" column as the index. 2. Show the shape of the DataFrame, the first 8 rows, and the last 8 rows of your DataFrame. 3. Show the data types of every column of your DataFrame. 4. There are some rows with missing data. Please drop these rows from the DataFrame. Show the shape of the DataFrame again. 5. Deleted the rows whose "engine-type" is "I" or "rotor". Save this as your new DataFrame for the following steps. 6. Create another DataFrame that consists of all the rows of Toyota cars. You can first use pandas.groupby() function to generate a GroupBy object, and then use GroupBy.get group() function to generate the DataFrame object for all Toyota cars. 7. Print the average mileage of each car company. You can make use of the GroupBy object created in Step 6. 8. Sort all cars by the price column in descending order, and save the sorted table in a new CSV file automobile_data_new.csv. You can use the pandas.to_csy() function. 9. Create a pivot table to calculate the average price of each car company. Use plot() function to draw a bar chart of the average prices without showing the legend. Set the y-label to "Average Price". 10. Create a pivot table to calculate the average horsepower and average price of each type of "num-of-cylinders". Covert the price data to the unit of 1,000 (i.e., divide the values by 1,000), and update the column label from "price" to "price(K$)". Sort the rows according to the average horsepower in descending order. Then plot a horizontal bar chart to visualize the average horsepower and average price.