Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- import seaborn as sns
- import warnings
- warnings.filterwarnings('ignore')
- df = pd.read_csv('housing.csv')
- df['total_bedrooms'].fillna(df['total_bedrooms'].median(), inplace=True)
- numerical_cols = df.select_dtypes(include=[np.number]).columns
- for col in numerical_cols:
- plt.figure(figsize=(10,6))
- df[col].plot(kind='hist', title=col, bins=60, edgecolor='black')
- plt.ylabel('Frequency')
- plt.show()
- for col in numerical_cols:
- plt.figure(figsize=(6, 6))
- sns.boxplot(df[col], color='blue')
- plt.title(col)
- plt.ylabel(col)
- plt.show()
- outliers_summary = {}
- for feature in numerical_cols:
- Q1 = df[feature].quantile(0.25)
- Q3 = df[feature].quantile(0.75)
- IQR = Q3 - Q1
- lower_bound = Q1 - 1.5 * IQR
- upper_bound = Q3 + 1.5 * IQR
- outliers = df[(df[feature] < lower_bound) | (df[feature] > upper_bound)]
- outliers_summary[feature] = len(outliers)
- print(f"{feature}: {len(outliers)} outliers")
Advertisement