...

/

Solution Review: Reading Auto MPG Dataset

Solution Review: Reading Auto MPG Dataset

This lesson provides the solution to the previous challenge.

We'll cover the following...

Reading the Dataset #

Press + to interact
import pandas as pd # calling pandas module
def read_csv():
# Define the column names as a list
names = ["mpg", "cylinders", "displacement", "horsepower", "weight", "acceleration", "model_year", "origin", "car_name"]
# Read in the CSV file from the webpage using the defined column names
df = pd.read_csv("auto-mpg.data", header=None, names=names, delim_whitespace=True)
return df.shape
# Calling the function and printing the result
print(read_csv())

According to the problem statement, we need to get the shape of Auto MPG Dataset as an output. In the code above, at line 1, we imported the pandas module for reading the dataset. Next, we implemented the function read_csv().

Look at its header at line 3. At line 6, we set the name of the ...