Species sepal & petal etc

 import pandas as pd

# Read the dataset

data = pd.read_csv("Iris.csv")

# Calculate the average measurements for each distinct species

avg_measurements = data.groupby("species").mean().reset_index()

# Create a new dataframe with species and average features

avg_features = avg_measurements[["species", "sepal_length", "sepal_width", "petal_length",

"petal_width"]]

# Rename the columns for better representation

avg_features.columns = ["Species", "Avg Sepal Length", "Avg Sepal Width", "Avg Petal

Length", "Avg Petal Width"]

# Print the new dataframe

print(avg_features)

Output

Species Avg Sepal Length Avg Sepal Width Avg Petal Length Avg Petal Width

0 setosa 5.006 3.428 1.462 0.246

1 versicolor 5.936 2.770 4.260 1.326

2 virginica 6.588 2.974 5.552 2.026


a. Which species is having the maximum sepal width?

max_sepal_width_species = avg_features.loc[avg_features["Avg Sepal Width"].idxmax(),

"Species"]

print("Species with maximum sepal width:", max_sepal_width_species)

Output

Species with maximum sepal width: setosa


b. What is the standard deviation of average petal length among all the species?

std_dev_petal_length = avg_features["Avg Petal Length"].std()

print("Standard deviation of average petal length:", std_dev_petal_length)

Output

Standard deviation of average petal length: 1.7540571093439357


c. Determine the species that have an average sepal length above 2.0.

species_above_2 = avg_features[avg_features["Avg Sepal Length"] > 2.0]["Species"]

print("Species with average sepal length above 2.0:", ", ".join(species_above_2))

Output

Species with average sepal length above 2.0: setosa, versicolor, virginica

Comments

Popular posts from this blog

what is Machenical Engineering

PHOTO ( CHINESE LADKA)

Arithmatic operations, factorial of a number, while loop, prime number, etc