<jupyter_start><jupyter_text>Automotive datasetThis dataset, collected on Kaggle by [Toramky](https://www.kaggle.com/toramky/automobile-dataset) consists of data From 1985 Ward's Automotive Yearbook. As stated in the description, the dataset consists in three types of entities:* The specification of an auto in terms of various characteristics,* Its assigned insurance risk rating,* Its normalized losses in use as compared to other carsThe second rating corresponds to the degree to which the auto is more risky than its price indicates. Cars are initially assigned a risk factor symbol associated with its price. Then, if it is more risky (or less), this symbol is adjusted by moving it up (or down) the scale. Actuarians call this process "symboling". A value of +3 indicates that the auto is risky, -3 that it is probably pretty safe.<jupyter_code>import pandas as pd 
data = pd.read_csv('C:\\Users\\gdasc\\Documents\\automotive\\datasets\\Automobile_data.csv')
pd.set_option('display.max_columns', None)

print(data.head())
print(data.shape)
print(data.info())<jupyter_output>symboling normalized-losses         make fuel-type aspiration num-of-doors  \
0          3                 ?  alfa-romero       gas        std          two   
1          3                 ?  alfa-romero       gas        std          two   
2          1                 ?  alfa-romero       gas        std          two   
3          2               164         audi       gas        std         four   
4          2               164         audi       gas        std         four   

    body-style drive-wheels engine-location  wheel-base  length  width  \
0  convertible          rwd           front        88.6   168.8   64.1   
1  convertible          rwd           front        88.6   168.8   64.1   
2    hatchback          rwd           front        94.5   171.2   65.5   
3        sedan          fwd           front        99.8   176.6   66.2   
4        sedan          4wd           front        99.4   176.6   66.4   

   height  curb-weight engine-type num-of-cylinders  engine-size fue[...]<jupyter_text>Clean up /1As I can see, some missing values are written as '?'. I need to replace them and impute their values.Since the cars where produced in the same year and probably share the same technology, I can impute the values basing on the mean.<jupyter_code>import numpy as np

data = data.replace('?', np.nan)
data.isna().any()
w_nan = ['normalized-losses','bore','stroke','horsepower','peak-rpm','price']
data[w_nan] = data[w_nan].astype(np.number)
data[w_nan] = data[w_nan].fillna(data[w_nan].mean())<jupyter_output><empty_output><jupyter_text>Clean up /2A whole different pair of shoes is about the num-of-doors column.Since the body-stile column has not missing values, I can assume that where the body stile is: hardtop, convertible and sedan, the number of doors is two. The other body-style should have four.<jupyter_code>#Create the dictionary
dict1 = {'two_doors' : ['hardtop', 'convertible', 'sedan'],
        'four_doors' : ['hatchback', 'wagon'] }

#Map num-of-doors
data['num-of-doors'] = data['num-of-doors'].fillna(data['body-style'].map(dict1))<jupyter_output><empty_output><jupyter_text>Clean up/3In the head of the ['make'] column, I've noticed that the glorious Alfa Romeo and Peugeot were miswritten.Let's check if there are other writing problems.<jupyter_code>data['make'].unique()

# rename with correct carachters.
data['make'] = data['make'].str.replace('alfa-romero', 'alfa romeo')
data['make'] = data['make'].str.replace('peugot','peugeot')
data['make'] = data['make'].str.title()
data['make']<jupyter_output><empty_output><jupyter_text>Database is ready for visualization and production.<jupyter_code>import matplotlib.pyplot as plt
import seaborn as sns<jupyter_output><empty_output><jupyter_text>Which car Manifacturer sold more cars in 1985?<jupyter_code>data['make'].value_counts().nlargest()
sns.countplot(x='make',order=data['make'].value_counts().index,data=data)
plt.title("Car sales in 1985")
plt.xlabel('Manifacturers')
plt.ylabel('Count')
plt.xticks(rotation=90)
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup