<kaggle_start><code>import pandas as pd
import sklearn

# importing dataset
df_train = pd.read_csv("/kaggle/input/home-data-for-ml-course/train.csv")
df_test = pd.read_csv("/kaggle/input/home-data-for-ml-course/test.csv")
# to simplify calling the dataframes each time
df1 = df_train
df2 = df_test


class primitive_analysis:
    def __init__(self):
        print("---train dataset overview:--- \n")
        print(df1.head(5))
        print(df1.tail(5))

    def info(self, df1, df2):
        print("\n---train dataset info :---\n")
        print(df1.info())
        print("\n---test dataset info :---\n")
        print(df2.info())

    def dimensions(self, df1, df2):
        print("\n---no. of dimensions [train] = ", df1.ndim)
        print("---no. of dimensions [test]  = ", df2.ndim)

    def size(self, df1, df2):
        print("\n---size of dataset [train] = ", df1.size)
        print("---size of dataset [test] = ", df2.size)

    def axes(self, df1, df2):
        print("\n---list of the labels [train]  ", df1.axes)
        print("\n---list of the labels [test]  ", df2.axes)

    def empty(self, df1, df2):
        print("is dataset empty? [train] ", df1.empty)
        print("is dataset empty? [test]  ", df2.empty)


obj_primitive = primitive_analysis()
obj_primitive.info(df1, df2)
obj_primitive.dimensions(df1, df2)
obj_primitive.axes(df1, df2)
obj_primitive.empty(df1, df2)


class data_cleaning:
    def __init__(self):
        pass

    def drop_columns(self, df1, df2):
        # df1["Alley"].fillna("Unknown", inplace = True)
        # drop df1["Alley"] column because of 1369/1459 null values
        if "Alley" in df1.columns:
            df1.drop(["Alley"], axis=1, inplace=True)
        # drop df1["PoolQC"] column because of 1453/1459 null values
        if "PoolQC" in df1.columns:
            df1.drop(["PoolQC"], axis=1, inplace=True)
        # drop df1["MiscFeature"] column because of 1406/1459 null values
        if "MiscFeature" in df1.columns:
            df1.drop(["MiscFeature"], axis=1, inplace=True)
        # drop df1["Fence"] column because of 1179/1459 null values
        if "Fence" in df1.columns:
            df1.drop(["Fence"], axis=1, inplace=True)
        # drop df1["FireplaceQu"] column because of 690/1459 null values
        if "FireplaceQu" in df1.columns:
            df1.drop(["FireplaceQu"], axis=1, inplace=True)
        return df1, df2
        """
        df1.dropna(inplace = True)
        df2.dropna(inplace = True)
        return df1, df2
        """

    def view_row_column_count(self, df1, df2):
        # view and print the row & column count of the dataset
        print(f"\n --- view the rows and column count of the dataset --- \n")
        print("[train] = ", df1.shape)
        print("[test]  =", df2.shape)

    def check_missing_values(self, df1, df2):
        # check and print missing values
        print(f"\n --- check missing values --- \n")
        total_nulls = df1.isnull().sum()
        for key, value in total_nulls.iteritems():
            print(key, ",", value)

    def check_duplicate(self, df1, df2):
        print("\n--- Duplicate items :---\n")
        duplicate = df1[df1.duplicated()]
        print(duplicate)

    def analyze_missing_values(self, df1, df2):
        # most of them are obj except for LotFrontage / GarageYrBlt which are float
        # consider best approaches to handle missing values in float and string
        # float
        # calculating mode for columns with missing values
        LotFrontage = df1["LotFrontage"].mode()
        MasVnrType = df1["MasVnrType"].mode()
        MasVnrArea = df1["MasVnrArea"].mode()
        BsmtQual = df1["BsmtQual"].mode()
        BsmtCond = df1["BsmtCond"].mode()
        BsmtExposure = df1["BsmtExposure"].mode()
        BsmtFinType1 = df1["BsmtFinType1"].mode()
        BsmtFinType2 = df1["BsmtFinType2"].mode()
        GarageType = df1["GarageType"].mode()
        GarageYrBlt = df1["GarageYrBlt"].mode()
        GarageFinish = df1["GarageFinish"].mode()
        GarageQual = df1["GarageQual"].mode()
        GarageCond = df1["GarageCond"].mode()
        """
        print("LotFrontage = ", LotFrontage) #0.351799
        print("MasVnrType = ", MasVnrType) 
        print("MasVnrArea = ", MasVnrArea) #0.477493
        print("BsmtQual = ", BsmtQual)
        print("BsmtCond = ", BsmtCond)
        print("BsmtExposure = ", BsmtExposure)
        print("BsmtFinType1 = ", BsmtFinType1)
        print("BsmtFinType2 = ", BsmtFinType2)
        print("GarageType = ", GarageType)
        print("GarageYrBlt = ", GarageYrBlt) #0.486362
        print("GarageFinish = ", GarageFinish)
        print("GarageQual = ", GarageQual)
        print("GarageCond = ", GarageCond)
        """
        # create new df > as one of the approaches for missing values
        df1_sample1 = df1
        # handling missing values in > LotFrontage , GarageYrBlt
        mean_LotFrontage = df1_sample1["LotFrontage"].mean()
        mean_GarageYrBlt = int(df1_sample1["GarageYrBlt"].mean())
        print("mean[GarageYrBlt] = ", mean_GarageYrBlt)
        print("mean[mean_LotFrontage] = ", mean_LotFrontage)
        # insert mean values in > LotFrontage , GarageYrBlt
        df1_sample1["LotFrontage"] = mean_LotFrontage
        df1_sample1["GarageYrBlt"] = mean_GarageYrBlt
        # df1_sample1 = df1_sample1.fillna(df.mean())
        df1_sample1.fillna({"LotFrontage": mean_LotFrontage}, inplace=True)
        # print(df1_sample1["MasVnrType"].to_string())
        # corr=df1_sample1['LotFrontage'].corr(df1_sample1['SalePrice'])
        # print(corr)
        # print(df1_sample1)
        # covariance
        # print("\n--- covariance ---\n")
        # print(df1.cov())
        # correlation
        print("\n--- correlation ---\n")
        print(df1.corr())
        # avg, mean,
        # print(statistics.mode(df1["MasVnrType"]))
        # print(MasVnrType[0] , "," , MasVnrArea[0] , "," ,  )
        # return df1, df2


obj_cleaning = data_cleaning()
obj_cleaning.view_row_column_count(df1, df2)
obj_cleaning.check_missing_values(df1, df2)
obj_cleaning.check_duplicate(df1, df2)
df1, df2 = obj_cleaning.drop_columns(df1, df2)
# df1, df2 = obj_cleaning.fill_na_fileds(df1, df2)
# obj_cleaning.analyze_missing_values(df1, df2)
print(df1.corr())


class EDA:
    def __init__(self):
        # print(df1.info())
        pass

    def convert_obj_cols_to_numeric(self, df1, df2):
        df1_sample1 = df1
        # print(df1_sample1["MasVnrType"].to_string())
        MSZoning_values = df1_sample1["MSZoning"].unique()
        Street_values = df1_sample1["Street"].unique()
        LotShape_values = df1_sample1["LotShape"].unique()
        LandContour_values = df1_sample1["LandContour"].unique()
        Utilities_values = df1_sample1["Utilities"].unique()
        LotConfig_values = df1_sample1["LotConfig"].unique()
        LandSlope_values = df1_sample1["LandSlope"].unique()
        Neighborhood_values = df1_sample1["Neighborhood"].unique()
        Condition1_values = df1_sample1["Condition1"].unique()
        Condition2_values = df1_sample1["Condition2"].unique()
        BldgType_values = df1_sample1["BldgType"].unique()
        HouseStyle_values = df1_sample1["HouseStyle"].unique()
        RoofStyle_values = df1_sample1["RoofStyle"].unique()
        RoofMatl_values = df1_sample1["RoofMatl"].unique()
        Exterior1st_values = df1_sample1["Exterior1st"].unique()
        Exterior2nd_values = df1_sample1["Exterior2nd"].unique()
        ExterQual_values = df1_sample1["ExterQual"].unique()
        ExterCond_values = df1_sample1["ExterCond"].unique()
        Foundation_values = df1_sample1["Foundation"].unique()
        BsmtQual_values = df1_sample1["BsmtQual"].unique()
        BsmtCond_values = df1_sample1["BsmtCond"].unique()
        BsmtExposure_values = df1_sample1["BsmtExposure"].unique()
        BsmtFinType1_values = df1_sample1["BsmtFinType1"].unique()
        BsmtFinType2_values = df1_sample1["BsmtFinType2"].unique()
        Heating_values = df1_sample1["Heating"].unique()
        HeatingQC_values = df1_sample1["HeatingQC"].unique()
        CentralAir_values = df1_sample1["CentralAir"].unique()
        Electrical_values = df1_sample1["Electrical"].unique()
        KitchenQual_values = df1_sample1["KitchenQual"].unique()
        Functional_values = df1_sample1["Functional"].unique()
        GarageType_values = df1_sample1["GarageType"].unique()
        GarageFinish_values = df1_sample1["GarageFinish"].unique()
        GarageQual_values = df1_sample1["GarageQual"].unique()
        GarageCond_values = df1_sample1["GarageCond"].unique()
        PavedDrive_values = df1_sample1["PavedDrive"].unique()
        SaleType_values = df1_sample1["SaleType"].unique()
        SaleCondition_values = df1_sample1["SaleCondition"].unique()
        # create a dictionary to keep obj values as a numeric
        df1_sample1["MasVnrType"] = df1_sample1["MasVnrType"].replace(
            ["None", "Stone", "BrkCmn", "BrkFace"], [0, 1, 2, 3]
        )
        df1_sample1["MSZoning"] = df1_sample1["MSZoning"].replace(
            ["RL", "RM", "C (all)", "FV", "RH"], [0, 1, 2, 3, 4]
        )
        df1_sample1["Street"] = df1_sample1["Street"].replace(["Pave", "Grvl"], [0, 1])
        df1_sample1["LotShape"] = df1_sample1["LotShape"].replace(
            ["Reg", "IR1", "IR2", "IR3"], [0, 1, 2, 3]
        )
        df1_sample1["LandContour"] = df1_sample1["LandContour"].replace(
            ["Lvl", "Bnk", "Low", "HLS"], [0, 1, 2, 3]
        )
        df1_sample1["Utilities"] = df1_sample1["Utilities"].replace(
            ["AllPub", "NoSeWa"], [0, 1]
        )
        df1_sample1["LotConfig"] = df1_sample1["LotConfig"].replace(
            ["Inside", "FR2", "Corner", "CulDSac", "FR3"], [0, 1, 2, 3, 4]
        )
        df1_sample1["LandSlope"] = df1_sample1["LandSlope"].replace(
            ["Gtl", "Mod", "Sev"], [0, 1, 2]
        )
        df1_sample1["Neighborhood"] = df1_sample1["Neighborhood"].replace(
            [
                "CollgCr",
                "Veenker",
                "Crawfor",
                "NoRidge",
                "Mitchel",
                "Somerst",
                "NWAmes",
                "OldTown",
                "BrkSide",
                "Sawyer",
                "NridgHt",
                "NAmes",
                "SawyerW",
                "IDOTRR",
                "MeadowV",
                "Edwards",
                "Timber",
                "Gilbert",
                "StoneBr",
                "ClearCr",
                "NPkVill",
                "Blmngtn",
                "BrDale",
                "SWISU",
                "Blueste",
            ],
            [
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                19,
                20,
                21,
                22,
                23,
                24,
            ],
        )
        df1_sample1["Condition1"] = df1_sample1["Condition1"].replace(
            ["Norm", "Feedr", "PosN", "Artery", "RRAe", "RRNn", "RRAn", "PosA", "RRNe"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8],
        )
        df1_sample1["Condition2"] = df1_sample1["Condition2"].replace(
            ["Norm", "Artery", "RRNn", "Feedr", "PosN", "PosA", "RRAn", "RRAe"],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["BldgType"] = df1_sample1["BldgType"].replace(
            ["1Fam", "2fmCon", "Duplex", "TwnhsE", "Twnhs"], [0, 1, 2, 3, 4]
        )
        df1_sample1["HouseStyle"] = df1_sample1["HouseStyle"].replace(
            [
                "2Story",
                "1Story",
                "1.5Fin",
                "1.5Unf",
                "SFoyer",
                "SLvl",
                "2.5Unf",
                "2.5Fin",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["RoofStyle"] = df1_sample1["RoofStyle"].replace(
            ["Gable", "Hip", "Gambrel", "Mansard", "Flat", "Shed"], [0, 1, 2, 3, 4, 5]
        )
        df1_sample1["RoofMatl"] = df1_sample1["RoofMatl"].replace(
            [
                "CompShg",
                "WdShngl",
                "Metal",
                "WdShake",
                "Membran",
                "Tar&Grv",
                "Roll",
                "ClyTile",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["Exterior1st"] = df1_sample1["Exterior1st"].replace(
            [
                "VinylSd",
                "MetalSd",
                "Wd Sdng",
                "HdBoard",
                "BrkFace",
                "WdShing",
                "CemntBd",
                "Plywood",
                "AsbShng",
                "Stucco",
                "BrkComm",
                "AsphShn",
                "Stone",
                "ImStucc",
                "CBlock",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
        )
        df1_sample1["Exterior2nd"] = df1_sample1["Exterior2nd"].replace(
            [
                "VinylSd",
                "MetalSd",
                "Wd Shng",
                "HdBoard",
                "Plywood",
                "Wd Sdng",
                "CmentBd",
                "BrkFace",
                "Stucco",
                "AsbShng",
                "Brk Cmn",
                "ImStucc",
                "AsphShn",
                "Stone",
                "Other",
                "CBlock",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
        )
        # df1_sample1['ExterQual'] = df1_sample1['ExterQual'].replace(['Gd' ,'TA', 'Ex', 'Fa'], [0,1,2,3])
        # df1_sample1['ExterCond'] = df1_sample1['ExterCond'].replace(['TA', 'Gd', 'Fa', 'Po', 'Ex'], [0,1,2,3,4])
        # df1_sample1['Foundation'] = df1_sample1['Foundation'].replace(['PConc' ,'CBlock', 'BrkTil', 'Wood', 'Slab', 'Stone'], [0,1,2,3,4,5])
        # df1_sample1['BsmtQual'] = df1_sample1['BsmtQual'].replace(['Gd' ,'TA', 'Ex','Fa'], [0,1,2,3])
        # df1_sample1['BsmtQual'] = df1_sample1['BsmtQual'].replace(['Gd' ,'TA', 'Ex','Fa'], [0,1,2,3])
        # df1_sample1['BsmtCond'] = df1_sample1['BsmtCond'].replace(['TA', 'Gd','Fa', 'Po'], [0,1,2,3])
        # df1_sample1['BsmtExposure'] = df1_sample1['BsmtExposure'].replace(['No','Gd', 'Mn', 'Av'], [0,1,2,3])
        # df1_sample1['BsmtFinType1'] = df1_sample1['BsmtFinType1'].replace(['GLQ','ALQ', 'Unf', 'Rec', 'BLQ', 'LwQ'], [0,1,2,3,4,5])
        # df1_sample1['BsmtFinType2'] = df1_sample1['BsmtFinType2'].replace(['Unf' ,'BLQ','ALQ', 'Rec', 'LwQ', 'GLQ'], [0,1,2,3,4,5])
        # df1_sample1['BsmtExposure'] = df1_sample1['BsmtExposure'].replace(['No','Gd', 'Mn', 'Av'], [0,1,2,3])
        # df1_sample1['Heating'] = df1_sample1['Heating'].replace(['GasA', 'GasW', 'Grav', 'Wall', 'OthW', 'Floor'], [0,1,2,3,4,5])
        # df1_sample1['HeatingQC'] = df1_sample1['HeatingQC'].replace(['Ex' ,'Gd', 'TA', 'Fa', 'Po'], [0,1,2,3,4])
        # df1_sample1['CentralAir'] = df1_sample1['CentralAir'].replace(['Y' ,'N'], [0,1])
        # df1_sample1['Electrical'] = df1_sample1['Electrical'].replace(['SBrkr', 'FuseF', 'FuseA', 'FuseP', 'Mix'], [0,1,2,3,4])
        # df1_sample1['KitchenQual'] = df1_sample1['KitchenQual'].replace(['Gd', 'TA', 'Ex', 'Fa'], [0,1,2,3])
        # df1_sample1['Functional'] = df1_sample1['Functional'].replace(['Typ', 'Min1', 'Maj1', 'Min2', 'Mod', 'Maj2', 'Sev'], [0,1,2,3,4,5,6])
        # df1_sample1['GarageType'] = df1_sample1['GarageType'].replace(['Attchd', 'Detchd', 'BuiltIn', 'CarPort', 'Basment', '2Types'], [0,1,2,3,4,5])
        # df1_sample1['GarageFinish'] = df1_sample1['GarageFinish'].replace(['RFn' ,'Unf', 'Fin'], [0,1,2])
        # df1_sample1['GarageQual'] = df1_sample1['GarageQual'].replace(['TA','Fa', 'Gd','Ex', 'Po'], [0,1,2,3,4])
        # df1_sample1['PavedDrive'] = df1_sample1['PavedDrive'].replace(['Y', 'N', 'P'], [0,1,2])
        df1_sample1["SaleType"] = df1_sample1["SaleType"].replace(
            ["WD", "New", "COD", "ConLD", "ConLI", "CWD", "ConLw", "Con", "Oth"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8],
        )
        df1_sample1["SaleCondition"] = df1_sample1["SaleCondition"].replace(
            ["Normal", "Abnorml", "Partial", "AdjLand", "Alloca", "Family"],
            [0, 1, 2, 3, 4, 5],
        )
        dic_columns = {
            "MasVnrType": ["None", "Stone", "BrkCmn", "BrkFace"],
            "MSZoning": ["RL", "RM", "C (all)", "FV", "RH"],
            "Street": ["Pave", "Grvl"],
            "LotShape": ["Reg", "IR1", "IR2", "IR3"],
            "LandContour": ["Lvl", "Bnk", "Low", "HLS"],
            "Utilities": ["AllPub", "NoSeWa"],
            "LotConfig": ["Inside", "FR2", "Corner", "CulDSac", "FR3"],
            "LandSlope": ["Gtl", "Mod", "Sev"],
            "RoofStyle": ["Gable", "Hip", "Gambrel", "Mansard", "Flat", "Shed"],
            "BsmtExposure": ["No", "Gd", "Mn", "Av"],
            "GarageFinish": ["RFn", "Unf", "Fin"],
            "SaleType": [
                "WD",
                "New",
                "COD",
                "ConLD",
                "ConLI",
                "CWD",
                "ConLw",
                "Con",
                "Oth",
            ],
            "SaleCondition": [
                "Normal",
                "Abnorml",
                "Partial",
                "AdjLand",
                "Alloca",
                "Family",
            ],
        }
        # print(df1_sample1.corr())
        print(df1_sample1.corr())

    def correlation(self, df1, df2):
        print(df1.corr())
        # [OverallQual / YearBuilt / YearRemodAdd / MasVnrArea] / BsmtFinSF1 / LotFrontage / WoodDeckSF / OpenPorchSF


obj_eda = EDA()
# obj_eda.correlation(df1, df2)
obj_eda.convert_obj_cols_to_numeric(df1, df2)
<|endoftext|>
[{"Id": 119399350, "ScriptId": 35008370, "ParentScriptVersionId": NaN, "ScriptLanguageId": 9, "AuthorUserId": 13475265, "CreationDate": "02/16/2023 19:53:21", "VersionNumber": 8.0, "Title": "Housing-Prices-Competition", "EvaluationDate": "02/16/2023", "IsChange": true, "TotalLines": 312.0, "LinesInsertedFromPrevious": 27.0, "LinesChangedFromPrevious": 0.0, "LinesUnchangedFromPrevious": 285.0, "LinesInsertedFromFork": NaN, "LinesDeletedFromFork": NaN, "LinesChangedFromFork": NaN, "LinesUnchangedFromFork": NaN, "TotalVotes": 0}]
import pandas as pd
import sklearn

# importing dataset
df_train = pd.read_csv("/kaggle/input/home-data-for-ml-course/train.csv")
df_test = pd.read_csv("/kaggle/input/home-data-for-ml-course/test.csv")
# to simplify calling the dataframes each time
df1 = df_train
df2 = df_test


class primitive_analysis:
    def __init__(self):
        print("---train dataset overview:--- \n")
        print(df1.head(5))
        print(df1.tail(5))

    def info(self, df1, df2):
        print("\n---train dataset info :---\n")
        print(df1.info())
        print("\n---test dataset info :---\n")
        print(df2.info())

    def dimensions(self, df1, df2):
        print("\n---no. of dimensions [train] = ", df1.ndim)
        print("---no. of dimensions [test]  = ", df2.ndim)

    def size(self, df1, df2):
        print("\n---size of dataset [train] = ", df1.size)
        print("---size of dataset [test] = ", df2.size)

    def axes(self, df1, df2):
        print("\n---list of the labels [train]  ", df1.axes)
        print("\n---list of the labels [test]  ", df2.axes)

    def empty(self, df1, df2):
        print("is dataset empty? [train] ", df1.empty)
        print("is dataset empty? [test]  ", df2.empty)


obj_primitive = primitive_analysis()
obj_primitive.info(df1, df2)
obj_primitive.dimensions(df1, df2)
obj_primitive.axes(df1, df2)
obj_primitive.empty(df1, df2)


class data_cleaning:
    def __init__(self):
        pass

    def drop_columns(self, df1, df2):
        # df1["Alley"].fillna("Unknown", inplace = True)
        # drop df1["Alley"] column because of 1369/1459 null values
        if "Alley" in df1.columns:
            df1.drop(["Alley"], axis=1, inplace=True)
        # drop df1["PoolQC"] column because of 1453/1459 null values
        if "PoolQC" in df1.columns:
            df1.drop(["PoolQC"], axis=1, inplace=True)
        # drop df1["MiscFeature"] column because of 1406/1459 null values
        if "MiscFeature" in df1.columns:
            df1.drop(["MiscFeature"], axis=1, inplace=True)
        # drop df1["Fence"] column because of 1179/1459 null values
        if "Fence" in df1.columns:
            df1.drop(["Fence"], axis=1, inplace=True)
        # drop df1["FireplaceQu"] column because of 690/1459 null values
        if "FireplaceQu" in df1.columns:
            df1.drop(["FireplaceQu"], axis=1, inplace=True)
        return df1, df2
        """
        df1.dropna(inplace = True)
        df2.dropna(inplace = True)
        return df1, df2
        """

    def view_row_column_count(self, df1, df2):
        # view and print the row & column count of the dataset
        print(f"\n --- view the rows and column count of the dataset --- \n")
        print("[train] = ", df1.shape)
        print("[test]  =", df2.shape)

    def check_missing_values(self, df1, df2):
        # check and print missing values
        print(f"\n --- check missing values --- \n")
        total_nulls = df1.isnull().sum()
        for key, value in total_nulls.iteritems():
            print(key, ",", value)

    def check_duplicate(self, df1, df2):
        print("\n--- Duplicate items :---\n")
        duplicate = df1[df1.duplicated()]
        print(duplicate)

    def analyze_missing_values(self, df1, df2):
        # most of them are obj except for LotFrontage / GarageYrBlt which are float
        # consider best approaches to handle missing values in float and string
        # float
        # calculating mode for columns with missing values
        LotFrontage = df1["LotFrontage"].mode()
        MasVnrType = df1["MasVnrType"].mode()
        MasVnrArea = df1["MasVnrArea"].mode()
        BsmtQual = df1["BsmtQual"].mode()
        BsmtCond = df1["BsmtCond"].mode()
        BsmtExposure = df1["BsmtExposure"].mode()
        BsmtFinType1 = df1["BsmtFinType1"].mode()
        BsmtFinType2 = df1["BsmtFinType2"].mode()
        GarageType = df1["GarageType"].mode()
        GarageYrBlt = df1["GarageYrBlt"].mode()
        GarageFinish = df1["GarageFinish"].mode()
        GarageQual = df1["GarageQual"].mode()
        GarageCond = df1["GarageCond"].mode()
        """
        print("LotFrontage = ", LotFrontage) #0.351799
        print("MasVnrType = ", MasVnrType) 
        print("MasVnrArea = ", MasVnrArea) #0.477493
        print("BsmtQual = ", BsmtQual)
        print("BsmtCond = ", BsmtCond)
        print("BsmtExposure = ", BsmtExposure)
        print("BsmtFinType1 = ", BsmtFinType1)
        print("BsmtFinType2 = ", BsmtFinType2)
        print("GarageType = ", GarageType)
        print("GarageYrBlt = ", GarageYrBlt) #0.486362
        print("GarageFinish = ", GarageFinish)
        print("GarageQual = ", GarageQual)
        print("GarageCond = ", GarageCond)
        """
        # create new df > as one of the approaches for missing values
        df1_sample1 = df1
        # handling missing values in > LotFrontage , GarageYrBlt
        mean_LotFrontage = df1_sample1["LotFrontage"].mean()
        mean_GarageYrBlt = int(df1_sample1["GarageYrBlt"].mean())
        print("mean[GarageYrBlt] = ", mean_GarageYrBlt)
        print("mean[mean_LotFrontage] = ", mean_LotFrontage)
        # insert mean values in > LotFrontage , GarageYrBlt
        df1_sample1["LotFrontage"] = mean_LotFrontage
        df1_sample1["GarageYrBlt"] = mean_GarageYrBlt
        # df1_sample1 = df1_sample1.fillna(df.mean())
        df1_sample1.fillna({"LotFrontage": mean_LotFrontage}, inplace=True)
        # print(df1_sample1["MasVnrType"].to_string())
        # corr=df1_sample1['LotFrontage'].corr(df1_sample1['SalePrice'])
        # print(corr)
        # print(df1_sample1)
        # covariance
        # print("\n--- covariance ---\n")
        # print(df1.cov())
        # correlation
        print("\n--- correlation ---\n")
        print(df1.corr())
        # avg, mean,
        # print(statistics.mode(df1["MasVnrType"]))
        # print(MasVnrType[0] , "," , MasVnrArea[0] , "," ,  )
        # return df1, df2


obj_cleaning = data_cleaning()
obj_cleaning.view_row_column_count(df1, df2)
obj_cleaning.check_missing_values(df1, df2)
obj_cleaning.check_duplicate(df1, df2)
df1, df2 = obj_cleaning.drop_columns(df1, df2)
# df1, df2 = obj_cleaning.fill_na_fileds(df1, df2)
# obj_cleaning.analyze_missing_values(df1, df2)
print(df1.corr())


class EDA:
    def __init__(self):
        # print(df1.info())
        pass

    def convert_obj_cols_to_numeric(self, df1, df2):
        df1_sample1 = df1
        # print(df1_sample1["MasVnrType"].to_string())
        MSZoning_values = df1_sample1["MSZoning"].unique()
        Street_values = df1_sample1["Street"].unique()
        LotShape_values = df1_sample1["LotShape"].unique()
        LandContour_values = df1_sample1["LandContour"].unique()
        Utilities_values = df1_sample1["Utilities"].unique()
        LotConfig_values = df1_sample1["LotConfig"].unique()
        LandSlope_values = df1_sample1["LandSlope"].unique()
        Neighborhood_values = df1_sample1["Neighborhood"].unique()
        Condition1_values = df1_sample1["Condition1"].unique()
        Condition2_values = df1_sample1["Condition2"].unique()
        BldgType_values = df1_sample1["BldgType"].unique()
        HouseStyle_values = df1_sample1["HouseStyle"].unique()
        RoofStyle_values = df1_sample1["RoofStyle"].unique()
        RoofMatl_values = df1_sample1["RoofMatl"].unique()
        Exterior1st_values = df1_sample1["Exterior1st"].unique()
        Exterior2nd_values = df1_sample1["Exterior2nd"].unique()
        ExterQual_values = df1_sample1["ExterQual"].unique()
        ExterCond_values = df1_sample1["ExterCond"].unique()
        Foundation_values = df1_sample1["Foundation"].unique()
        BsmtQual_values = df1_sample1["BsmtQual"].unique()
        BsmtCond_values = df1_sample1["BsmtCond"].unique()
        BsmtExposure_values = df1_sample1["BsmtExposure"].unique()
        BsmtFinType1_values = df1_sample1["BsmtFinType1"].unique()
        BsmtFinType2_values = df1_sample1["BsmtFinType2"].unique()
        Heating_values = df1_sample1["Heating"].unique()
        HeatingQC_values = df1_sample1["HeatingQC"].unique()
        CentralAir_values = df1_sample1["CentralAir"].unique()
        Electrical_values = df1_sample1["Electrical"].unique()
        KitchenQual_values = df1_sample1["KitchenQual"].unique()
        Functional_values = df1_sample1["Functional"].unique()
        GarageType_values = df1_sample1["GarageType"].unique()
        GarageFinish_values = df1_sample1["GarageFinish"].unique()
        GarageQual_values = df1_sample1["GarageQual"].unique()
        GarageCond_values = df1_sample1["GarageCond"].unique()
        PavedDrive_values = df1_sample1["PavedDrive"].unique()
        SaleType_values = df1_sample1["SaleType"].unique()
        SaleCondition_values = df1_sample1["SaleCondition"].unique()
        # create a dictionary to keep obj values as a numeric
        df1_sample1["MasVnrType"] = df1_sample1["MasVnrType"].replace(
            ["None", "Stone", "BrkCmn", "BrkFace"], [0, 1, 2, 3]
        )
        df1_sample1["MSZoning"] = df1_sample1["MSZoning"].replace(
            ["RL", "RM", "C (all)", "FV", "RH"], [0, 1, 2, 3, 4]
        )
        df1_sample1["Street"] = df1_sample1["Street"].replace(["Pave", "Grvl"], [0, 1])
        df1_sample1["LotShape"] = df1_sample1["LotShape"].replace(
            ["Reg", "IR1", "IR2", "IR3"], [0, 1, 2, 3]
        )
        df1_sample1["LandContour"] = df1_sample1["LandContour"].replace(
            ["Lvl", "Bnk", "Low", "HLS"], [0, 1, 2, 3]
        )
        df1_sample1["Utilities"] = df1_sample1["Utilities"].replace(
            ["AllPub", "NoSeWa"], [0, 1]
        )
        df1_sample1["LotConfig"] = df1_sample1["LotConfig"].replace(
            ["Inside", "FR2", "Corner", "CulDSac", "FR3"], [0, 1, 2, 3, 4]
        )
        df1_sample1["LandSlope"] = df1_sample1["LandSlope"].replace(
            ["Gtl", "Mod", "Sev"], [0, 1, 2]
        )
        df1_sample1["Neighborhood"] = df1_sample1["Neighborhood"].replace(
            [
                "CollgCr",
                "Veenker",
                "Crawfor",
                "NoRidge",
                "Mitchel",
                "Somerst",
                "NWAmes",
                "OldTown",
                "BrkSide",
                "Sawyer",
                "NridgHt",
                "NAmes",
                "SawyerW",
                "IDOTRR",
                "MeadowV",
                "Edwards",
                "Timber",
                "Gilbert",
                "StoneBr",
                "ClearCr",
                "NPkVill",
                "Blmngtn",
                "BrDale",
                "SWISU",
                "Blueste",
            ],
            [
                0,
                1,
                2,
                3,
                4,
                5,
                6,
                7,
                8,
                9,
                10,
                11,
                12,
                13,
                14,
                15,
                16,
                17,
                18,
                19,
                20,
                21,
                22,
                23,
                24,
            ],
        )
        df1_sample1["Condition1"] = df1_sample1["Condition1"].replace(
            ["Norm", "Feedr", "PosN", "Artery", "RRAe", "RRNn", "RRAn", "PosA", "RRNe"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8],
        )
        df1_sample1["Condition2"] = df1_sample1["Condition2"].replace(
            ["Norm", "Artery", "RRNn", "Feedr", "PosN", "PosA", "RRAn", "RRAe"],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["BldgType"] = df1_sample1["BldgType"].replace(
            ["1Fam", "2fmCon", "Duplex", "TwnhsE", "Twnhs"], [0, 1, 2, 3, 4]
        )
        df1_sample1["HouseStyle"] = df1_sample1["HouseStyle"].replace(
            [
                "2Story",
                "1Story",
                "1.5Fin",
                "1.5Unf",
                "SFoyer",
                "SLvl",
                "2.5Unf",
                "2.5Fin",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["RoofStyle"] = df1_sample1["RoofStyle"].replace(
            ["Gable", "Hip", "Gambrel", "Mansard", "Flat", "Shed"], [0, 1, 2, 3, 4, 5]
        )
        df1_sample1["RoofMatl"] = df1_sample1["RoofMatl"].replace(
            [
                "CompShg",
                "WdShngl",
                "Metal",
                "WdShake",
                "Membran",
                "Tar&Grv",
                "Roll",
                "ClyTile",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7],
        )
        df1_sample1["Exterior1st"] = df1_sample1["Exterior1st"].replace(
            [
                "VinylSd",
                "MetalSd",
                "Wd Sdng",
                "HdBoard",
                "BrkFace",
                "WdShing",
                "CemntBd",
                "Plywood",
                "AsbShng",
                "Stucco",
                "BrkComm",
                "AsphShn",
                "Stone",
                "ImStucc",
                "CBlock",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14],
        )
        df1_sample1["Exterior2nd"] = df1_sample1["Exterior2nd"].replace(
            [
                "VinylSd",
                "MetalSd",
                "Wd Shng",
                "HdBoard",
                "Plywood",
                "Wd Sdng",
                "CmentBd",
                "BrkFace",
                "Stucco",
                "AsbShng",
                "Brk Cmn",
                "ImStucc",
                "AsphShn",
                "Stone",
                "Other",
                "CBlock",
            ],
            [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15],
        )
        # df1_sample1['ExterQual'] = df1_sample1['ExterQual'].replace(['Gd' ,'TA', 'Ex', 'Fa'], [0,1,2,3])
        # df1_sample1['ExterCond'] = df1_sample1['ExterCond'].replace(['TA', 'Gd', 'Fa', 'Po', 'Ex'], [0,1,2,3,4])
        # df1_sample1['Foundation'] = df1_sample1['Foundation'].replace(['PConc' ,'CBlock', 'BrkTil', 'Wood', 'Slab', 'Stone'], [0,1,2,3,4,5])
        # df1_sample1['BsmtQual'] = df1_sample1['BsmtQual'].replace(['Gd' ,'TA', 'Ex','Fa'], [0,1,2,3])
        # df1_sample1['BsmtQual'] = df1_sample1['BsmtQual'].replace(['Gd' ,'TA', 'Ex','Fa'], [0,1,2,3])
        # df1_sample1['BsmtCond'] = df1_sample1['BsmtCond'].replace(['TA', 'Gd','Fa', 'Po'], [0,1,2,3])
        # df1_sample1['BsmtExposure'] = df1_sample1['BsmtExposure'].replace(['No','Gd', 'Mn', 'Av'], [0,1,2,3])
        # df1_sample1['BsmtFinType1'] = df1_sample1['BsmtFinType1'].replace(['GLQ','ALQ', 'Unf', 'Rec', 'BLQ', 'LwQ'], [0,1,2,3,4,5])
        # df1_sample1['BsmtFinType2'] = df1_sample1['BsmtFinType2'].replace(['Unf' ,'BLQ','ALQ', 'Rec', 'LwQ', 'GLQ'], [0,1,2,3,4,5])
        # df1_sample1['BsmtExposure'] = df1_sample1['BsmtExposure'].replace(['No','Gd', 'Mn', 'Av'], [0,1,2,3])
        # df1_sample1['Heating'] = df1_sample1['Heating'].replace(['GasA', 'GasW', 'Grav', 'Wall', 'OthW', 'Floor'], [0,1,2,3,4,5])
        # df1_sample1['HeatingQC'] = df1_sample1['HeatingQC'].replace(['Ex' ,'Gd', 'TA', 'Fa', 'Po'], [0,1,2,3,4])
        # df1_sample1['CentralAir'] = df1_sample1['CentralAir'].replace(['Y' ,'N'], [0,1])
        # df1_sample1['Electrical'] = df1_sample1['Electrical'].replace(['SBrkr', 'FuseF', 'FuseA', 'FuseP', 'Mix'], [0,1,2,3,4])
        # df1_sample1['KitchenQual'] = df1_sample1['KitchenQual'].replace(['Gd', 'TA', 'Ex', 'Fa'], [0,1,2,3])
        # df1_sample1['Functional'] = df1_sample1['Functional'].replace(['Typ', 'Min1', 'Maj1', 'Min2', 'Mod', 'Maj2', 'Sev'], [0,1,2,3,4,5,6])
        # df1_sample1['GarageType'] = df1_sample1['GarageType'].replace(['Attchd', 'Detchd', 'BuiltIn', 'CarPort', 'Basment', '2Types'], [0,1,2,3,4,5])
        # df1_sample1['GarageFinish'] = df1_sample1['GarageFinish'].replace(['RFn' ,'Unf', 'Fin'], [0,1,2])
        # df1_sample1['GarageQual'] = df1_sample1['GarageQual'].replace(['TA','Fa', 'Gd','Ex', 'Po'], [0,1,2,3,4])
        # df1_sample1['PavedDrive'] = df1_sample1['PavedDrive'].replace(['Y', 'N', 'P'], [0,1,2])
        df1_sample1["SaleType"] = df1_sample1["SaleType"].replace(
            ["WD", "New", "COD", "ConLD", "ConLI", "CWD", "ConLw", "Con", "Oth"],
            [0, 1, 2, 3, 4, 5, 6, 7, 8],
        )
        df1_sample1["SaleCondition"] = df1_sample1["SaleCondition"].replace(
            ["Normal", "Abnorml", "Partial", "AdjLand", "Alloca", "Family"],
            [0, 1, 2, 3, 4, 5],
        )
        dic_columns = {
            "MasVnrType": ["None", "Stone", "BrkCmn", "BrkFace"],
            "MSZoning": ["RL", "RM", "C (all)", "FV", "RH"],
            "Street": ["Pave", "Grvl"],
            "LotShape": ["Reg", "IR1", "IR2", "IR3"],
            "LandContour": ["Lvl", "Bnk", "Low", "HLS"],
            "Utilities": ["AllPub", "NoSeWa"],
            "LotConfig": ["Inside", "FR2", "Corner", "CulDSac", "FR3"],
            "LandSlope": ["Gtl", "Mod", "Sev"],
            "RoofStyle": ["Gable", "Hip", "Gambrel", "Mansard", "Flat", "Shed"],
            "BsmtExposure": ["No", "Gd", "Mn", "Av"],
            "GarageFinish": ["RFn", "Unf", "Fin"],
            "SaleType": [
                "WD",
                "New",
                "COD",
                "ConLD",
                "ConLI",
                "CWD",
                "ConLw",
                "Con",
                "Oth",
            ],
            "SaleCondition": [
                "Normal",
                "Abnorml",
                "Partial",
                "AdjLand",
                "Alloca",
                "Family",
            ],
        }
        # print(df1_sample1.corr())
        print(df1_sample1.corr())

    def correlation(self, df1, df2):
        print(df1.corr())
        # [OverallQual / YearBuilt / YearRemodAdd / MasVnrArea] / BsmtFinSF1 / LotFrontage / WoodDeckSF / OpenPorchSF


obj_eda = EDA()
# obj_eda.correlation(df1, df2)
obj_eda.convert_obj_cols_to_numeric(df1, df2)
