2
2
import numpy as np
import pandas as pd
np.random.seed(42)
# Create a DataFrame
df = pd.DataFrame(data_with_outliers, columns=["Value"])
plt.figure(figsize=(8, 5))
sns.boxplot(x=df["Value"], color="skyblue")
plt.show()
Q1 = df["Value"].quantile(0.25)
Q3 = df["Value"].quantile(0.75)
IQR = Q3 - Q1
# Identify outliers
median_value = df["Value"].median()
df["Value_Handled"] = np.where(
median_value,
df["Value"],
plt.figure(figsize=(8, 5))
sns.boxplot(x=df["Value_Handled"], color="lightgreen")
plt.show()
OR
data = fetch_california_housing(as_frame=True)
df = data['data']
axs[0].scatter(df['HouseAge'], df['AveRooms'])
axs[0].set_xlabel('House Age')
axs[0].set_ylabel('Average Rooms')
axs[1].scatter(df['HouseAge'], df['AveBedrms'])
axs[1].set_xlabel('House Age')
axs[1].set_ylabel('Average Bedrooms')
plt.tight_layout()
plt.show()