import pandas as pd
import numpy as np
df = pd.read_csv('carsinfo.csv')
As we discussd before, we should handle "?" for following columns before converting their datatypes:
normalized_losses object
bore object
stroke object
horsepower object
peak_rpm object
price object
Therefore, let's Get rid of "?" , replace it with "Nan" , and then convert datatypes
df["normalized_losses"] = df["normalized_losses"].replace({'?': np.nan}).dropna().astype(int)
df["bore"] = df["bore"].replace({'?': np.nan}).dropna().astype(float)
df["stroke"] = df["stroke"].replace({'?': np.nan}).dropna().astype(float)
df["horsepower"] = df["horsepower"].replace({'?': np.nan}).dropna().astype(float)
df["peak_rpm"] = df["peak_rpm"].replace({'?': np.nan}).dropna().astype(float)
df["price"] = df["price"].replace({'?': np.nan}).dropna().astype(float)
df.head()
# Let's check datatypes again to see modifications
df.dtypes