<jupyter_start><jupyter_text>**Determine how many missing values are present in each column**<jupyter_code>df.isna().sum().sort_values()
# most of the columns have a lot of missing values 

plt.figure(figsize=(20,7))
df.isna().sum().sort_values().plot(kind='bar' )
plt.title("The count of missing values in each column.");<jupyter_output><empty_output><jupyter_text>**Determine the total amount of missing values**<jupyter_code>df.isna().sum().sum()<jupyter_output><empty_output><jupyter_text><jupyter_code><jupyter_output><empty_output><jupyter_text>Create a histogram or bar chart of what the distribution of values looks like before handling NaN values and after. Each plot must have the following- Axis Labels- Title<jupyter_code># create hist for all columns in the dataset

axes = df.hist(figsize=(15, 15), grid = False)

plt.tight_layout()
plt.show()<jupyter_output><empty_output><jupyter_text>**Choose a column and replace NaN values with the mean**<jupyter_code># replace NaN with mean in 'Hunger'

miss_val_before_hunger = df['Hunger'].isna().sum()

print(f'Number of missing values in Hunger is: {miss_val_before_hunger}')
print('Hunger mean is: ',df['Hunger'].mean())
df['Hunger'].replace(np.nan, df['Hunger'].mean(),inplace=True)

miss_val_after_hunger = df['Hunger'].isna().sum()

print(f'Number of missing values in Hunger is: {miss_val_after_hunger}')

df['Hunger'].hist(grid=False);<jupyter_output>Number of missing values in Hunger is: 3
Hunger mean is:  3.4960952380952386
Number of missing values in Hunger is: 0<jupyter_text>**Choose a column and replace NaN values with the median**<jupyter_code># replace NaN with median in 'Cost'

miss_val_before_Cost = df['Cost'].isna().sum()

print(f'Number of missing values in Cost is: {miss_val_before_Cost}')
print('Cost median is: ',df['Cost'].median())
df['Cost'].replace(np.nan, df['Cost'].median(),inplace=True)

miss_val_after_Cost = df['Cost'].isna().sum()

print(f'Number of missing values in Cost is: {miss_val_after_Cost}')

df['Cost'].hist(grid=False);<jupyter_output>Number of missing values in Cost is: 7
Cost median is:  6.99
Number of missing values in Cost is: 0<jupyter_text>**Choose a column and replace NaN values with the mode**<jupyter_code># replace NaN with mode in 'Salsa'

miss_val_before_Salsa = df['Salsa'].isna().sum()

print(f'Number of missing values in Salsa is: {miss_val_before_Salsa}')
print('Salsa mode is: ',df['Salsa'].median())
df['Salsa'].replace(np.nan, df['Salsa'].median(),inplace=True)

miss_val_after_Salsa = df['Salsa'].isna().sum()

print(f'Number of missing values in Salsa is: {miss_val_after_Salsa}')

df['Salsa'].hist(grid=False);<jupyter_output>Number of missing values in Salsa is: 25
Salsa mode is:  3.5
Number of missing values in Salsa is: 0<jupyter_text>**Choose a column and replace NaN values with your own value**<jupyter_code># replace NaN with 3.5 in 'Meat'

miss_val_before_Meat = df['Meat'].isna().sum()

print(f'Number of missing values in Meat is: {miss_val_before_Meat}')
df['Meat'].replace(np.nan, 3.5,inplace=True)

miss_val_after_Meat = df['Meat'].isna().sum()

print(f'Number of missing values in Meat is: {miss_val_after_Meat}')

df['Meat'].hist(grid=False);<jupyter_output>Number of missing values in Meat is: 14
Number of missing values in Meat is: 0<jupyter_text>**Choose a column and use backwards filling**<jupyter_code># fill backwards in 'temp'

miss_val_before_Temp = df['Temp'].isna().sum()

print(f'Number of missing values in Temp is: {miss_val_before_Temp}')
df['Temp'].fillna(method='bfill')

miss_val_after_Temp = df['Temp'].isna().sum()

print(f'Number of missing values in Temp is: {miss_val_after_Temp}')

df['Temp'].hist(grid=False);<jupyter_output>Number of missing values in Temp is: 20
Number of missing values in Temp is: 20<jupyter_text>**Choose a column and use forwards filling**<jupyter_code># fill forwards in 'Length'

miss_val_before_Length = df['Length'].isna().sum()

print(f'Number of missing values in Temp is: {miss_val_before_Length}')
df['Length'].fillna(method='bfill')

miss_val_after_Length = df['Length'].isna().sum()

print(f'Number of missing values in Length is: {miss_val_after_Length}')

df['Length'].hist(grid=False);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14241779039507926, 'fraction_numerical': 0.011118996924532765, 'mean_word_length': 7.162162162162162, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 36, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '367810', 'license': 'MIT', 'n_tokens_mistral': 1559, 'n_tokens_neox': 1468, 'n_words': 395, 'path': 'Python/Week 3/Day11_Matplotlib.ipynb', 'repo_name': 'ZarahShibli/Data-Science-Bootcamp', 'size': '4227'}