Chapter 02: Statistical Visualizations Using Matplotlib and Seaborn
Activity 4: Line Graphs with the Object-Oriented API and Pandas DataFrames
Import the required libraries in the Jupyter notebook and read the dataset from the Auto-MPG dataset repository:
%matplotlib inline import matplotlib as mpl import matplotlib.pyplot as pltimport numpy as np import pandas as pd url = "https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data" df = pd.read_csv(url)
Provide the column names to simplify the dataset, as illustrated here:
column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name']
Now read the new dataset with column names and display it:
df = pd.read_csv(url, names= column_names, delim_whitespace=True) df.head()
The plot is as follows:

Figure 2.29: The auto-mpg DataFrame
Convert the horsepower and year data types to float and integer using the following command:
df.loc[df.horsepower == '?', 'horsepower'] = np.nan df...