import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
import seaborn as sns
os.chdir(r'D:\projects\wordpress\ex185') 
os.getcwd()
url = "https://archive.ics.uci.edu/ml/machine-learning-databases/auto-mpg/auto-mpg.data"
df = pd.read_csv(url)
column_names = ['mpg', 'cylinders', 'displacement', 'horsepower', 'weight', 'acceleration', 'year', 'origin', 'name']
df = pd.read_csv(url, names= column_names, delim_whitespace=True)
df.loc[df.horsepower == '?', 'horsepower'] = np.nan
df['horsepower'] = pd.to_numeric(df['horsepower'])
df['full_date'] = pd.to_datetime(df.year, format='%y')
df['year'] = df['full_date'].dt.year
fig, ax = plt.subplots()
ax.scatter(x = df['horsepower'], y=df['weight'])
plt.savefig('ex185a.jpg', dpi=300)
sns.scatterplot(data=df, x='horsepower', y='weight', hue='cylinders', size='mpg')
plt.savefig('ex185b.jpg', dpi=300)

Discover more from Tips and Hints for Aerospace Engineers

Subscribe now to keep reading and get access to the full archive.

Continue reading