0% found this document useful (0 votes)
8 views3 pages

AI Code

The document outlines a Python script that downloads the iris dataset from the UCI Machine Learning Repository, saves it locally, and processes it using pandas. It includes steps for loading the data, checking for duplicates, normalizing specific columns, and saving the cleaned data to a new CSV file. The script also performs basic data analysis such as displaying the dataset's information and descriptive statistics.

Uploaded by

kunalbose6534
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

AI Code

The document outlines a Python script that downloads the iris dataset from the UCI Machine Learning Repository, saves it locally, and processes it using pandas. It includes steps for loading the data, checking for duplicates, normalizing specific columns, and saving the cleaned data to a new CSV file. The script also performs basic data analysis such as displaying the dataset's information and descriptive statistics.

Uploaded by

kunalbose6534
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

import os

import requests

# Create the 'data' directory if it doesn't exist

if not [Link]('data'):

[Link]('data')

# URL for the [Link] dataset (without header) from UCI Machine Learning Repository

# This file does not have a header, which aligns with header=0 and
names=column_name

iris_data_url = "[Link]
databases/iris/[Link]"

local_file_path = "data/[Link]"

# Download the file

response = [Link](iris_data_url)

response.raise_for_status() # Raise an exception for bad status codes

with open(local_file_path, 'wb') as f:

[Link]([Link])

print(f"Downloaded [Link] to {local_file_path}")


import pandas as pd

column_name=['sepal_length','sepal_width','petal_length','petal_width','species']

iris_data=pd.read_csv('data/[Link]',names=column_name)

iris_data.head()

print(iris_data.info())

print(iris_data.describe())

print(iris_data['species'].value_counts())

iris_data.dropna(inplace=True)

duplicate_rows = iris_data.duplicated()

print("Number of duplicate rows",duplicate_rows.sum())

from [Link] import StandardScaler

cols_to_normalize = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']

scaler=StandardScaler()

scaled_data=scaler.fit(iris_data[cols_to_normalize])

iris_data[cols_to_normalize]=[Link](iris_data[cols_to_normalize])

print(iris_data.describe)

iris_data.to_csv('cleaned_iris.csv',index=False)

You might also like