Ex-01_DS_Data_Cleansing

AIM

To read the given data and perform data cleaning and save the cleaned data to a file.

Explanation

Data cleaning is the process of preparing data for analysis by removing or modifying data that is incorrect ,incompleted , irrelevant , duplicated or improperly formatted. Data cleaning is not simply about erasing data ,but rather finding a way to maximize datasets accuracy without necessarily deleting the information.

ALGORITHM

STEP 1

Read the given Data

STEP 2

Get the information about the data

STEP 3

Remove the null values from the data

STEP 4

Save the Clean data to the file

STEP 5

Remove outliers using IQR

STEP 6

Use zscore of to remove outliers

CODE and OUTPUT

import pandas as pd

df=pd.read_csv("/content/SAMPLEIDS.csv")

df

Screenshot 2024-08-20 105954

df.isnull().sum()

Screenshot 2024-08-20 110159

df.isnull().any()

Screenshot 2024-08-20 110307

df.dropna()

Screenshot 2024-08-20 110423

df.fillna(0)

Screenshot 2024-08-20 110536

df.fillna(method="ffill")

Screenshot 2024-08-20 111041

df.fillna(method='bfill')

Screenshot 2024-08-20 111148

df_dropped = df.dropna()

df_dropped

Screenshot 2024-08-20 111244

df.fillna({'GENDER':'MALE','NAME':'SRI','ADDRESS':'POONAMALEE','M1':98,'M2':87,'M3':76,'M4':92,'TOTAL':305,'AVG':89.999999})

Screenshot 2024-08-20 111342

import pandas as pd

ir=pd.read_csv('/content/iris.csv')

ir

Screenshot 2024-08-20 111435

ir.describe()

Screenshot 2024-08-20 111520

import seaborn as sns

sns.boxplot(x='sepal_width',data=ir)

Screenshot 2024-08-20 111610

c1=ir.sepal_width.quantile(0.25)

c3=ir.sepal_width.quantile(0.75)

iq=c3-c1

print(c3)

3.3

rid=ir[((ir.sepal_width<(c1-1.5iq))|(ir.sepal_width>(c3+1.5iq)))]

rid['sepal_width']

Screenshot 2024-08-20 111734

delid=ir[~((ir.sepal_width<(c1-1.5iq))|(ir.sepal_width>(c3+1.5iq)))]

delid

Screenshot 2024-08-20 111823

sns.boxplot(x='sepal_width',data=delid)

Screenshot 2024-08-20 111911

import matplotlib.pyplot as plt

import pandas as pd

import numpy as np

import scipy.stats as stats

dataset = pd.read_csv('/content/heights.csv')

dataset

Screenshot 2024-08-20 112020

df = pd.read_csv('/content/heights.csv')

q1=df['height'].quantile(0.25)

q2=df['height'].quantile(0.5)

q3=df['height'].quantile(0.75)

iqr=q3-q1

iqr

0.9249999999999998

low=q1-1.5*iqr

print(low)

3.8625000000000003

high= q3+1.5*iqr

print(high)

7.5625

df1=df[(df['height']>=low) & (df['height']<=high)]

df1

Screenshot 2024-08-20 112508

z = np.abs(stats.zscore(df['height']))

z

Screenshot 2024-08-20 112708

df1=df[z<3]

df1

Screenshot 2024-08-20 112833

RESULT

Thus we have cleaned the data and removed the outliers by detection using IQR and Z-score method.