0% found this document useful (0 votes)
16 views4 pages

Experiment 3

Uploaded by

MR. GAMER
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)
16 views4 pages

Experiment 3

Uploaded by

MR. GAMER
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
You are on page 1/ 4

In [1]: import numpy


speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]

x = numpy.mean(speed)

print(x)

89.76923076923077

In [2]: import numpy



speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]

x = numpy.median(speed)

print(x)

87.0

In [7]: import numpy



speed = [99,86,87,88,86,103,87,94,78,77,85,86]

x = numpy.median(speed)

print(x)

86.5

In [8]: from scipy import stats



speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]

x = stats.mode(speed)

print(x)

ModeResult(mode=array([86]), count=array([3]))

In [9]: n_num = [1, 2, 3, 4, 5]


n = len(n_num)

get_sum = sum(n_num)
mean = get_sum/n

print("Mean / Average is : " + str(mean))

Mean / Average is : 3.0


In [10]: n_num = [1, 2, 3, 4, 5]
n = len(n_num)
n_num.sort()

if n % 2 == 0:
median1 = n_num[n//2]
median2 = n_num[n//2-1]
median = (median1 + median2)/2
else:
median = n_num[n//2]
print("Median is : " + str(median))

Median is : 3

In [16]: from collections import Counter



n_num = [1, 2, 3, 4, 5, 5]
n = len(n_num)

data = Counter(n_num)
get_mode = dict(data)
mode = [k for k, v in get_mode.items() if v == max(list(data.values()))]

if len(mode) == n:
get_mode = "No mode found"
else:
get_mode = "Mode is/are : " + ', '.join(map(str,mode))
print(get_mode)

Mode is/are : 5

In [17]: import pandas as pd



df = pd.DataFrame({'A' : ['a', 'b', 'c', 'c', 'a', 'b'],
'B' : [0, 1, 1, 0, 1, 0]}, dtype = "category")
df.dtypes

Out[17]: A category
B category
dtype: object

In [18]: print(df)

print(df.groupby(['A']). count().reset_index())

A B
0 a 0
1 b 1
2 c 1
3 c 0
4 a 1
5 b 0
A B
0 a 2
1 b 2
2 c 2
In [19]: import pandas as pd

df = pd.DataFrame({'A' : ['a', 'b', 'c', 'c', 'a', 'b'],
'B' : [0, 1, 1, 0, 1, 0],
'C' : [7, 8, 9, 5, 3, 6]})

df['A'] = df['A'].astype('category')

print(df)

print(df.groupby(['A', 'B']).mean().reset_index())

A B C
0 a 0 7
1 b 1 8
2 c 1 9
3 c 0 5
4 a 1 3
5 b 0 6
A B C
0 a 0 7
1 a 1 3
2 b 0 6
3 b 1 8
4 c 0 5
5 c 1 9
In [22]: import pandas as pd

data = pd.read_csv(r"D:\College\TE\SEM-2\Practical\DSBDA\3\Iris.csv")

print('Iris-setosa')
setosa= data['Species'] == 'Iris-setosa'
print(data[setosa].describe())

print('\nIris-versicolor')
versicolor= data['Species'] == 'Iris-versicolor'
print(data[versicolor].describe())

print('\nIris-virginica')
virginica = data['Species'] == 'Iris-virginica'
print (data[virginica].describe())

Iris-setosa
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
count 50.00000 50.00000 50.000000 50.000000 50.00000
mean 25.50000 5.00600 3.418000 1.464000 0.24400
std 14.57738 0.35249 0.381024 0.173511 0.10721
min 1.00000 4.30000 2.300000 1.000000 0.10000
25% 13.25000 4.80000 3.125000 1.400000 0.20000
50% 25.50000 5.00000 3.400000 1.500000 0.20000
75% 37.75000 5.20000 3.675000 1.575000 0.30000
max 50.00000 5.80000 4.400000 1.900000 0.60000

Iris-versicolor
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
count 50.00000 50.000000 50.000000 50.000000 50.000000
mean 75.50000 5.936000 2.770000 4.260000 1.326000
std 14.57738 0.516171 0.313798 0.469911 0.197753
min 51.00000 4.900000 2.000000 3.000000 1.000000
25% 63.25000 5.600000 2.525000 4.000000 1.200000
50% 75.50000 5.900000 2.800000 4.350000 1.300000
75% 87.75000 6.300000 3.000000 4.600000 1.500000
max 100.00000 7.000000 3.400000 5.100000 1.800000

Iris-virginica
Id SepalLengthCm SepalWidthCm PetalLengthCm PetalWidthCm
count 50.00000 50.00000 50.000000 50.000000 50.00000
mean 125.50000 6.58800 2.974000 5.552000 2.02600
std 14.57738 0.63588 0.322497 0.551895 0.27465
min 101.00000 4.90000 2.200000 4.500000 1.40000
25% 113.25000 6.22500 2.800000 5.100000 1.80000
50% 125.50000 6.50000 3.000000 5.550000 2.00000
75% 137.75000 6.90000 3.175000 5.875000 2.30000
max 150.00000 7.90000 3.800000 6.900000 2.50000

In [ ]: ​

You might also like