"""
### Import Libraries
"""
import os
import re
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import seaborn as sns
"""
### Load the Data
"""
df = pd.read_csv("/kaggle/input/sri-lanka-furniture-prices-dataset/furniture_prices.csv")
df.head()
"""
### Data Cleaning
"""
# Converting Columns into numbers
# Return nan for prices which are listed as negotiable
def extract_num(row):
    try:
        amount = row.split(" ")[-1]
        return int(re.sub(r"[.,]", "", amount))
    except:
        np.nan
df["Price"] = df["Price"].apply(extract_num)
df["City"] = df["Location"].apply(lambda x: x.split(",")[0])
df["District"] = df["Location"].apply(lambda x: x.split(",")[-1])
df = df.drop("Location", axis=1)
df.head()
"""
### EDA
"""
# check stats of numeric columns
df.describe()
# Checking the null values 
df.isnull().sum()
plt.figure(figsize=(12,6))
sns.heatmap(df.isnull(),cbar=False,cmap="Set1",yticklabels=False);
"""
### Data Viz
"""
# Most popular furniture types

top_10_fur = df[["published_date", "Furniture_Type"]].groupby("Furniture_Type").agg(['count'])['published_date']['count'].sort_values(ascending=False)
fig = sns.barplot( x = top_10_fur.index, y = top_10_fur.values)
fig.set_xticklabels(labels=top_10_fur.index , rotation=45)
fig.set_ylabel("Number of Furniture Items in the Dataset")
fig.set_xlabel("Furniture Type")
fig.set_title("Most Popular Furniture Types");
# Top 10 Cities by Number of Furniture stold

top_10_city = df[["published_date", "City"]].groupby("City").agg(['count'])["published_date"]['count'].sort_values(ascending=False)[:10]
fig = sns.barplot( x = top_10_city.index, y = top_10_city.values)
fig.set_xticklabels(labels=top_10_city.index , rotation=45)
fig.set_ylabel("Number of Furniture Items in the Dataset")
fig.set_xlabel("City Name")
fig.set_title("Top 10 Cities by Number of Furniture stold");
# Top 10 Districts by Number of Furniture stold

top_10_dist = df[["published_date", "District"]].groupby("District").agg(['count'])["published_date"]['count'].sort_values(ascending=False)[:10]
fig = sns.barplot( x = top_10_dist.index, y = top_10_dist.values)
fig.set_xticklabels(labels=top_10_dist.index , rotation=45)
fig.set_ylabel("Number of Furniture Items in the Dataset")
fig.set_xlabel("District Name")
fig.set_title("Top 10 Districts by Number of Furniture stold");
# Distibution of seller types
fig = sns.countplot(data= df, x="Seller_type")
fig.set_ylabel("Number of Sellers")
fig.set_xlabel("Seller Type")
fig.set_title("Seller Type Distribution");
# Top 10 Sellers by Number of Furniture stold

top_10_sell = df[["published_date", "Seller_name"]].groupby("Seller_name").agg(['count'])["published_date"]['count'].sort_values(ascending=False)[:10]
fig = sns.barplot( x = top_10_sell.index, y = top_10_sell.values)
fig.set_xticklabels(labels=top_10_sell.index , rotation=45)
fig.set_ylabel("Number of Furniture Items in the Dataset")
fig.set_xlabel("Selelr Name")
fig.set_title("Top 10 Sellers by Number of Furniture stold");
# Top 10 Sellers by Total Revenue of Furniture stold

top_10_sell = df[["Price", "Seller_name"]].groupby("Seller_name").agg(['sum'])["Price"]['sum'].sort_values(ascending=False)[:10]
fig = sns.barplot( x = top_10_sell.index, y = top_10_sell.values)
fig.set_xticklabels(labels=top_10_sell.index , rotation=45)
fig.set_ylabel("Total Cost of Items sold in rupess(lkr)")
fig.set_xlabel("Seller Name")
fig.set_title("Top 10 Sellers by Total Revenue of Furniture stold");