Skip to main content

1. Download iris dataset file. Read this csv file using read_csv() function. Take samples from entire dataset. Display maximum and minimum values of all numeric attributes. 2. Continue with above dataset, find number of records for each distinct value of class attribute. Consider entire dataset and not the samples. 3. Display column-wise mean, and median for iris dataset from Q.4 (Hint: Use mean() and median() functions of pandas dataframe.



 """import pandas as pd
import numpy as np
df=pd.read_csv("Iris.csv")
print("Random Samples : ",df.sample(10))
print("Maximum value of numeric attribute : ")
print(df.max(axis=None))
print("Minimum value of numeric attribute :)
print(np.min(df))
================================================"""

from pandas import *
import numpy as np
import scipy.stats as s
df=read_csv("Iris.csv")
print(df.sample(10))
print(df)
print(df.dtypes)

print("min and max value spealLengthCm")
print(max(df["SepalLengthCm"]))
print(min(df["SepalLengthCm"]))

print("min and max value petalLength")
print(max(df["PetalLengthCm"]))
print(min(df["PetalLengthCm"]))
print("----------------------------------------------------------------------------------------------------------------------------------------")
print(df.info())
print("-----------------------------------------------------------------------------------------------------------------------------------------")
print("Mean:-")
print("SepalLengthCm Mean : ",s.tmean(df["SepalLengthCm"]).round(2))
print("SepalWidthCm Mean : ",s.tmean(df["SepalWidthCm"]).round(2))
print("PetalLengthCm Mean : ",s.tmean(df["PetalLengthCm"]).round(2))
print("PetalWidthCm Mean : ",s.tmean(df["PetalWidthCm"]).round(2))

print("Median:-")
print("SepalLengthCm Median : ",np.median(df["SepalLengthCm"]).round(2))
print("SepalWidthCm Median : ",np.median(df["SepalWidthCm"]).round(2))
print("PetalLengthCm Median: ",np.median(df["PetalLengthCm"]).round(2))
print("PetalWidthCm Median: ",np.median(df["PetalWidthCm"]).round(2))


"""OUTPUT-
~/Desktop/FDS/Assignment no-2/Set B$ python3 B1.py
      Id  SepalLengthCm  SepalWidthCm  PetalLengthCm  PetalWidthCm          Species
11    12            4.8           3.4            1.6           0.2      Iris-setosa
20    21            5.4           3.4            1.7           0.2      Iris-setosa
76    77            6.8           2.8            4.8           1.4  Iris-versicolor
86    87            6.7           3.1            4.7           1.5  Iris-versicolor
50    51            7.0           3.2            4.7           1.4  Iris-versicolor
129  130            7.2           3.0            5.8           1.6   Iris-virginica
120  121            6.9           3.2            5.7           2.3   Iris-virginica
2      3            4.7           3.2            1.3           0.2      Iris-setosa
12    13            4.8           3.0            1.4           0.1      Iris-setosa
147  148            6.5           3.0            5.2           2.0   Iris-virginica
      Id  SepalLengthCm  SepalWidthCm  PetalLengthCm  PetalWidthCm         Species
0      1            5.1           3.5            1.4           0.2     Iris-setosa
1      2            4.9           3.0            1.4           0.2     Iris-setosa
2      3            4.7           3.2            1.3           0.2     Iris-setosa
3      4            4.6           3.1            1.5           0.2     Iris-setosa
4      5            5.0           3.6            1.4           0.2     Iris-setosa
..   ...            ...           ...            ...           ...             ...
145  146            6.7           3.0            5.2           2.3  Iris-virginica
146  147            6.3           2.5            5.0           1.9  Iris-virginica
147  148            6.5           3.0            5.2           2.0  Iris-virginica
148  149            6.2           3.4            5.4           2.3  Iris-virginica
149  150            5.9           3.0            5.1           1.8  Iris-virginica

[150 rows x 6 columns]
Id                 int64
SepalLengthCm    float64
SepalWidthCm     float64
PetalLengthCm    float64
PetalWidthCm     float64
Species           object
dtype: object
min and max value spealLengthCm
7.9
4.3
min and max value petalLength
6.9
1.0
----------------------------------------------------------------------------------------------------------------------------------------
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 150 entries, 0 to 149
Data columns (total 6 columns):
 #   Column         Non-Null Count  Dtype  
---  ------         --------------  -----  
 0   Id             150 non-null    int64  
 1   SepalLengthCm  150 non-null    float64
 2   SepalWidthCm   150 non-null    float64
 3   PetalLengthCm  150 non-null    float64
 4   PetalWidthCm   150 non-null    float64
 5   Species        150 non-null    object
dtypes: float64(4), int64(1), object(1)
memory usage: 7.2+ KB
None
-----------------------------------------------------------------------------------------------------------------------------------------
Mean:-
SepalLengthCm Mean :  5.84
SepalWidthCm Mean :  3.05
PetalLengthCm Mean :  3.76
PetalWidthCm Mean :  1.2

Median:-
SepalLengthCm Median :  5.8
SepalWidthCm Median :  3.0
PetalLengthCm Median:  4.35
PetalWidthCm Median:  1.3
"""

Comments

Popular posts from this blog

Write a program to read book information (bookid, bookname, bookprice, bookqty) in file “book.dat”. Write a menu driven program to perform the following operations using Random access file: i. Search for a specific book by name. ii. Display all book and total cost

  import java . io .*; import java . util .*; class Book {       String name , id ;       int qty ;       double price , total ;       Book ( String i , String n , String p , String q )      {               name = n ;               id = i ;               qty = Integer . parseInt ( q );               price = Double . parseDouble ( p );               total = qty * price ;      }       public String toString ()      {               System . out . println ( "name\t id\t qty\t price\t total" );               String s = name + "\t" + id + "\t" + qty + "\t" + price + "\t" + total ;           ...

Define a class MyDate (day, month, year) with methods to accept and display a MyDate object. Accept date as dd, mm, yyyy. Throw user defined exception “InvalidDateException” if the date is invalid. Examples of invalid dates : 03 15 2019, 31 6 2000, 29 2 2021

  import java . io .*; import java . util .*; class InvalidDateException extends Exception {       InvalidDateException ()       {               System . out . println ( "Invalid Date" );       } } class MyDate {       int day , mon , yr ;       void accept ( int d , int m , int y )       {             day = d ;             mon = m ;             yr = y ;       }       void display ()       {             System . out . println ( "Date is valid : " + day + "/" + mon + "/" + yr );       } } class Date {       public static void main ( String args []) throws Exception       {             Scanner sc = new Sca...

Write a Java program to design a screen using Awt that will take a user name and password. If the user name and password are not same, raise an Exception with appropriate message. User can have 3 login chances only. Use clear button to clear the TextFields.

  import java . awt .*; import java . awt . event .*; import javax . swing .*; class InvalidPasswordException extends Exception {       InvalidPasswordException ()       {             System . out . println ( "Username and password is not same" );       } } public class Password extends Frame implements ActionListener {       Label uname , upass ;       TextField nametext ;       TextField passtext , msg ;       Button login , Clear ;       Panel p ;       int attempt = 0 ;       char c = '*' ;             public void login ()       {             p = new Panel ();             uname = new Label ( "Username : " , Label . CENTER );             upass = n...