image_output_1.png
import matplotlib.pyplot as plt

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import seaborn as sns

import seaborn as sns
import matplotlib.pyplot as plt
df = pd.read_csv('/kaggle/input/house-rent-prediction-dataset/House_Rent_Dataset.csv')

colors = ['#E557C4', '#57C4E5', '#293241']

def count(df, x, ax, main_color):
    ax.bar_label(ax.containers[0], color='black', fontsize='large')
    ax.tick_params(axis='y', which='both', left=False, right=False, labelleft=False)
    ax.tick_params(axis='x', which='both', bottom=False, top=False)
    sns.despine(ax=ax, left=True)

count_cols = ['Area Type', 'City', 'Furnishing Status', 'Tenant Preferred', "Bathroom", 'Point of Contact', "BHK"] 

fig, axs = plt.subplots(4, 2, figsize=(20, 22), sharey=True)

for i, col in enumerate(count_cols):
    r_i = i // 2
    c_i = i% 2

    count(df, col, axs[r_i][c_i], colors[0])
    

fig.delaxes(axs[3,1])

plt.show()

df = df[~(df['Area Type'] == 'Built Area')]
df = df[~(df['Point of Contact'] == 'Contact Builder')]
df = df[~(df['Bathroom'] > 6)]

df['Floor House'] = df['Floor'].str.split(' ').str.get(0)
df['Floor Building'] = df['Floor'].str.split(' ').str.get(-1)
df.drop('Floor', axis=1, inplace=True)

df.loc[df['Floor House'] == 'Ground', 'Floor House'] = 0
df.loc[df['Floor Building'] == 'Ground', 'Floor Building'] = 0
df.loc[df['Floor House'] == 'Lower', 'Floor House'] = 0
df.loc[df['Floor House'] == 'Upper', 'Floor House'] = df.loc[df['Floor House'] == 'Upper', 'Floor Building']

def hist(df, x, ax, main_color, meanline=True, mean_color=colors[2]):
    ax.tick_params(axis='y', which='both', left=False, right=False)
    sns.despine(ax=ax, left=True)

numeric_cols = ["Posted On", "Size", "Floor House", "Floor Building"]

fig, axs = plt.subplots(2, 2, figsize=(30, 15))

for i, num_col in enumerate(numeric_cols): 
    
    is_not_date = (num_col != "Posted On")
    
    r_i = i // 2 
    c_i = i % 2
    
    hist(df, num_col, axs[r_i][c_i], colors[1], meanline=is_not_date)
    

plt.show()

fig, axs = plt.subplots(1, 2, figsize=(20, 6))
for ax in axs:
    sns.stripplot(y=df['Rent'], ax=ax, color=colors[1], size=3, alpha=0.7, linewidth=0.1, edgecolor='black')
    ax.axhline(np.mean(df['Rent']), linestyle='--', color=colors[0], label='Mean', linewidth=1)
    ax.axhline(np.median(df['Rent']), linestyle=':', color=colors[2], label='Median', linewidth=1)
    ax.set_ylabel('')
    ax.set_xlabel('Rent')
    ax.tick_params(axis='y', which='both', left=False, right=False)
    ax.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False)
    sns.despine(ax=ax, left=True, bottom=True)
    ax.grid(axis='y', linewidth=0.2)
    ax.legend()
axs[0].set(title='Without logaritmic scale on y-axis')
axs[1].set(yscale='log', title='With logaritmic scale on y-axis')
plt.show()