1
+ {
2
+ "nbformat" : 4 ,
3
+ "nbformat_minor" : 0 ,
4
+ "metadata" : {
5
+ "colab" : {
6
+ "provenance" : [],
7
+ "collapsed_sections" : [],
8
+ "authorship_tag" : " ABX9TyN8dM3gWIdgceyg9ajI2jjm" ,
9
+ "include_colab_link" : true
10
+ },
11
+ "kernelspec" : {
12
+ "name" : " python3" ,
13
+ "display_name" : " Python 3"
14
+ },
15
+ "language_info" : {
16
+ "name" : " python"
17
+ }
18
+ },
19
+ "cells" : [
20
+ {
21
+ "cell_type" : " markdown" ,
22
+ "metadata" : {
23
+ "id" : " view-in-github" ,
24
+ "colab_type" : " text"
25
+ },
26
+ "source" : [
27
+ " <a href=\" https://colab.research.google.com/github/DeepthiTabithaBennet/Python_AppliedStatistics/blob/main/Percentile_Quartile.ipynb\" target=\" _parent\" ><img src=\" https://colab.research.google.com/assets/colab-badge.svg\" alt=\" Open In Colab\" /></a>"
28
+ ]
29
+ },
30
+ {
31
+ "cell_type" : " code" ,
32
+ "metadata" : {
33
+ "id" : " cazqRe9wvLVG"
34
+ },
35
+ "source" : [
36
+ " # Written by Deepthi Tabitha Bennet\n " ,
37
+ " \n " ,
38
+ " import numpy as np\n " ,
39
+ " import math\n " ,
40
+ " \n " ,
41
+ " arr = [32, 56, 47, 87, 98, 36, 87, 38, 97, 4, 26, 94, 95, 90, 24, 7, 90, 63]\n " ,
42
+ " arr.sort()"
43
+ ],
44
+ "execution_count" : null ,
45
+ "outputs" : []
46
+ },
47
+ {
48
+ "cell_type" : " markdown" ,
49
+ "metadata" : {
50
+ "id" : " NZONcT3PwOzC"
51
+ },
52
+ "source" : [
53
+ " **Percentile**"
54
+ ]
55
+ },
56
+ {
57
+ "cell_type" : " code" ,
58
+ "metadata" : {
59
+ "colab" : {
60
+ "base_uri" : " https://localhost:8080/"
61
+ },
62
+ "id" : " ftYS1KCvw307" ,
63
+ "outputId" : " 5b5283b7-83e4-49f6-ba72-25ec0327fea8"
64
+ },
65
+ "source" : [
66
+ " p = int(input(\" Enter the Percentile required : \" ))\n " ,
67
+ " \n " ,
68
+ " # Using Libraries\n " ,
69
+ " percentile1 = np.percentile(arr, p)\n " ,
70
+ " print(percentile1)\n " ,
71
+ " \n " ,
72
+ " # Without using Libraries\n " ,
73
+ " \n " ,
74
+ " i = p * len(arr) / 100\n " ,
75
+ " \n " ,
76
+ " if i.is_integer():\n " ,
77
+ " x = (arr[int(i-1)] + arr[int(i)]) / 2\n " ,
78
+ " print(int(x))\n " ,
79
+ " \n " ,
80
+ " else:\n " ,
81
+ " x = math.ceil(i)\n " ,
82
+ " print(arr[x-1])\n "
83
+ ],
84
+ "execution_count" : null ,
85
+ "outputs" : [
86
+ {
87
+ "output_type" : " stream" ,
88
+ "name" : " stdout" ,
89
+ "text" : [
90
+ " Enter the Percentile required : 60\n " ,
91
+ " 87.0\n " ,
92
+ " 87\n "
93
+ ]
94
+ }
95
+ ]
96
+ },
97
+ {
98
+ "cell_type" : " markdown" ,
99
+ "metadata" : {
100
+ "id" : " MsWoYUx5wOrq"
101
+ },
102
+ "source" : [
103
+ " **Quartile**"
104
+ ]
105
+ },
106
+ {
107
+ "cell_type" : " code" ,
108
+ "metadata" : {
109
+ "id" : " soU_AhUQy0ke" ,
110
+ "colab" : {
111
+ "base_uri" : " https://localhost:8080/"
112
+ },
113
+ "outputId" : " 176e41d1-c7f7-4414-89fb-64c3c4475be4"
114
+ },
115
+ "source" : [
116
+ " # Using Libraries\n " ,
117
+ " \n " ,
118
+ " Q1 = np.quantile(arr,.25)\n " ,
119
+ " print(\" The Quartile Q1 is : \" , Q1)\n " ,
120
+ " \n " ,
121
+ " Q2 = np.quantile(arr,.50)\n " ,
122
+ " print(\" The Quartile Q2 is : \" , Q2)\n " ,
123
+ " \n " ,
124
+ " Q3 = np.quantile(arr,.75)\n " ,
125
+ " print(\" The Quartile Q3 is : \" , Q3)\n " ,
126
+ " \n " ,
127
+ " # Without using Libraries\n " ,
128
+ " \n " ,
129
+ " n = len (arr)\n " ,
130
+ " \n " ,
131
+ " Q1 = (25/100)*n\n " ,
132
+ " Q2 = (50/100)*n\n " ,
133
+ " Q3 = (75/100)*n\n " ,
134
+ " \n " ,
135
+ " if Q1.is_integer():\n " ,
136
+ " x = (arr[int(Q1-1)] + arr[int(Q1)]) / 2\n " ,
137
+ " print(\" The Quartile Q1 is : \" , int(x))\n " ,
138
+ " else:\n " ,
139
+ " x = math.ceil(Q1)\n " ,
140
+ " print(\" The Quartile Q1 is : \" , arr[x-1] + 1)\n " ,
141
+ " \n " ,
142
+ " if Q2.is_integer():\n " ,
143
+ " z = (arr[int(Q2-1)] + arr[int(Q2)]) / 2\n " ,
144
+ " print(\" The Quartile Q2 is : \" , int(z))\n " ,
145
+ " else:\n " ,
146
+ " z = math.ceil(Q2)\n " ,
147
+ " print(\" The Quartile Q2 is : \" , arr[z-1])\n " ,
148
+ " if Q3.is_integer():\n " ,
149
+ " y = (arr[int(Q3-1)] + arr[int(Q3)]) / 2\n " ,
150
+ " print(\" The Quartile Q3 is : \" ,int(y))\n " ,
151
+ " else:\n " ,
152
+ " y = math.ceil(Q3)\n " ,
153
+ " print(\" The Quartile Q3 is : \" , arr[y-1])\n "
154
+ ],
155
+ "execution_count" : null ,
156
+ "outputs" : [
157
+ {
158
+ "output_type" : " stream" ,
159
+ "name" : " stdout" ,
160
+ "text" : [
161
+ " The Quartile Q1 is : 33.0\n " ,
162
+ " The Quartile Q2 is : 59.5\n " ,
163
+ " The Quartile Q3 is : 90.0\n " ,
164
+ " The Quartile Q1 is : 33\n " ,
165
+ " The Quartile Q2 is : 59\n " ,
166
+ " The Quartile Q3 is : 90\n "
167
+ ]
168
+ }
169
+ ]
170
+ }
171
+ ]
172
+ }
0 commit comments