<jupyter_start><jupyter_text>Deal with missing data  1. Drop data         a. drop the whole row        b. drop the whole column    2. Replace data        a. replace it by mean        b. replace it by frequency        c. replace it based on other functions<jupyter_code>df["normalized-losses"].replace(np.nan,df["normalized-losses"].astype("float").mean(axis=0), inplace = True)
df["stroke"].replace(np.nan,df["stroke"].astype("float").mean(axis=0), inplace = True)
df["bore"].replace(np.nan,df["bore"].astype("float").mean(axis=0), inplace = True)
df["horsepower"].replace(np.nan,df["horsepower"].astype("float").mean(axis=0), inplace = True)
df["peak-rpm"].replace(np.nan,df["peak-rpm"].astype("float").mean(axis=0), inplace = True)


df['num-of-doors'].value_counts()
df['num-of-doors'].value_counts().idxmax()
df['num-of-doors'].replace(np.nan, df['num-of-doors'].value_counts().idxmax(), inplace = True)
# reset index, because we droped two rows

df.reset_index(drop = True, inplace = True)
df.head()
df.dtypes
df[['bore','stroke','price','peak-rpm']] = df[['bore','stroke','price','peak-rpm']].astype("float") 
df[["normalized-losses"]] = df[["normalized-losses"]].astype("int")
print("data type changed")
df.head(5)
df['city-L/100km'] = 235/df['city-mpg']
df.head(5)

df.rename(columns={"city-mpg":"city-L/100km"}, inplace = True)
df.head()
# replace (origianl value) by (original value)/(maximum value)
df['length'] = df['length']/df['length'].max()
df['width'] = df['width']/df['width'].max()
df['height'] = df['height']/df['height'].max()

df[['length','width','height']].head()

arr = np.arange( 1, 10, 5)
print(arr)
df['horsepower'] = df['horsepower'].astype(int, inplace = True)

print(df['horsepower'].min())
print(df['horsepower'].max())

bandwidth = (df['horsepower'].max()-df['horsepower'].min())/4
print(bandwidth)


min1 = df['horsepower'].min()
max1 = df['horsepower'].max()

print(min1)
print(max1)

bins= np.arange(min1,max1, bandwidth)


print(bins)



group_names = ['low','medium','high']
#cutting into categories using cut function

df['horsepower-bin'] = pd.cut(df['horsepower'],bins,labels = group_names, include_lowest=True)
df[['horsepower','horsepower-bin']].head(20)
# data Visualisation

%matplotlib inline
import matplotlib as plt
from matplotlib import pyplot

plt.pyplot.hist(df['horsepower'],bins = 3)
plt.pyplot.xlabel("horsepower")
plt.pyplot.ylabel("count")
plt.pyplot.title("horsepower bins")
df.columns
dummy_variable1 = pd.get_dummies(df['fuel-type'])
dummy_variable1.head()

dummy_variable1.rename(columns= {'fuel-type-gas':'gas','fuel-type-diesel':'diesel'}, inplace=True)
dummy_variable1.head()
# merge data frame df and dummy_variable1
df = pd.concat([df, dummy_variable1], axis=1)

# drop original column fuel type from df

df.drop('fuel-type', axis=1, inplace=True)
df.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.20960392569225378, 'fraction_numerical': 0.014020329477742727, 'mean_word_length': 6.29923273657289, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '408037', 'license': 'MIT', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1026, 'n_words': 184, 'path': 'IBM task 1 &2 lab.ipynb', 'repo_name': 'ajsharma22/futureAutomobilePredictor', 'size': '2853'}