UfpdsMAR2025 - 1.ipynb - Colab 16apr2025
UfpdsMAR2025 - 1.ipynb - Colab 16apr2025
ipynb - Colab
1 print('Navrachana\t\t\t\tUniversity')
2 print("Vadodara")
3 print("BTech, BCA, BBA BSc-Bio, Chem")
Navrachana University
Vadodara
BTech, BCA, BBA BSc-Bio, Chem
1 a=300
2 print("value of a is ",a)
3 b=500
4 print("Value of b is ",b)
5 sum=a+b
6 print("Addition of ",a," and ",b," is ",sum)
value of a is 300
Value of b is 500
Addition of 300 and 500 is 800
1 x=10
2 y=3
3 sub=x-y
4 mul=x*y
5 div=x/y #Floating point division
6 di=x//y #Integer division omit decimal values
7 rem=x%y
8 rai=x**y
9 print("Subtraction is",sub)
10 print("Product is",mul)
11 print("Division is ",div)
12 print("Integer Division is ",di)
13 print("Remainder is ",rem)
14 print("raised to ",rai)
15
Subtraction is 7
Product is 30
Division is 3.3333333333333335
Integer Division is 3
Remainder is 1
raised to 1000
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 1/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
Write a Python Program to input Employee Name, age, basic salary from keyboard. Calculate DA as 45% of basic salary, HRA as
57% of basic salary and PF as 9% of basic salary.Also calculate net salary as basic salary+DA+HRA-PF. Display all the data in proper
salary slip format as below /////////////////
Empoyee Id : 2355
, <, >=, <=, != (not equal to), == (equal to) used to writing a condition Logical Operator and, or are logical operators used to check
multiple conditions simultaneously
1 a=6
2 if(a>=0):
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 2/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
3 print("Postive")
4 else:
5 print("Negative")
Postive
1 x=int(input("Enter a number:"))
2 rem=x%2
3 #print(rem)
4 if(rem==0):
5 print("EVEN")
6 else:
7 print("ODD")
Enter a number:17
ODD
1 print("Bank of ABC")
2 print("~~~~~~~~~~~")
3 balance=60000
4 print("Your balance is", balance)
5 print("1. Deposit \n2. Withdraw")
6 x=int(input("Enter your choice:"))
7 if(x==1):
8 dep=int(input("Enter Deposit amount:"))
9 balance=balance+dep
10 print("Now your balance is", balance)
11 elif(x==2):
12 withd=int(input("Enter Withdraw amount:"))
13 if(withd>(balance-5000)):
14 print("Insufficient Balance")
15 else:
16 balance=balance-withd
17
18 print("Now your balance is", balance)
19
Bank of ABC
~~~~~~~~~~~
Your balance is 60000
1. Deposit
2. Withdraw
Enter your choice:2
Enter Withdraw amount:40000
Now your balance is 20000
Write a program to display Student details. Input Student Name, roll no, marks of any 3 subjects out of 100. Display total,
Percentage, Status (pass/fail) and grades. If students scores more than 40 marks in each subject then the status is pass, otherwise
fail. Calculate grade if only student is pass. Grades must be
>=90% - A+
>=80% - A
>=70% - B+
>=60% - B
>=50% - C
>=40% - D
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 3/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
<40% - F
LOOPS in Python Loops enable programmers to repeat lines of code based on some condition There are two types of loop in
Python
1. While loop
2. for loop
while loop syntax initialize variable while(condition): few statements upgrade variable
Write a program to display Navrachana University 5 times without using while loop
1 print("Navrachana University\n"*5)
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 4/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
1 a=1
2 while(a<=5):
3 print("Navrachana University")
4 a=a+1
Navrachana University
Navrachana University
Navrachana University
Navrachana University
Navrachana University
1 #program to print 1 2 3 4 5
2 a=1
3 while(a<=100):
4 print(a)
5 a=a+1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 5/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
1 #program to print 100 to 1
2 a=100
3 while(a>=1):
4 print(a)
5 a=a-1
100
99
98
97
96
95
94
93
92
91
90
89
88
87
86
85
84
83
82
81
80
79
78
77
76
75
74
73
72
71
70
69
68
67
66
65
64
63
62
61
60
59
58
57
56
55
54
53
52
51
50
49
48
47
46
45
44
43
1
3
5
7
9
11
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 6/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
13
15
17
19
21
23
25
27
29
31
33
35
37
39
41
43
45
47
49
51
53
55
57
59
61
63
65
67
69
71
73
75
77
79
81
83
85
87
89
91
93
95
97
99
2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 7/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
58
60
62
64
66
68
70
72
74
76
78
80
82
84
86
88
90
92
94
96
98
100
2
4
8
16
32
64
128
256
512
1024
1 a=1024
2 while(a>=2):
3 print(a)
4 a=a//2
1024
512
256
128
64
32
16
8
4
2
1 num=int(input("Enter a number"))
2 ans=""
3 a=1
4 while(a<=10):
5 ans=num*a
6 print(num," X ",a," = ",ans)
7 a=a+1
8
Enter a number9
9 X 1 = 9
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 8/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
9 X 2 = 18
9 X 3 = 27
9 X 4 = 36
9 X 5 = 45
9 X 6 = 54
9 X 7 = 63
9 X 8 = 72
9 X 9 = 81
9 X 10 = 90
1
2
3
4
5
1 #program to print 5 to 1
2 for a in range(5,0,-1):
3 print(a)
5
4
3
2
1
1 #program to print 5 to 1
2 for a in range(1,101,2):
3 print(a)
1 a=[8,12,17,78,90,34] #list
2 print(a)
3 i=0
4 while(i<=5):
5 print(a[i])
6 i=i+1
7
1 a=[8,12,17,78,90,34] #list
2 print(a)
3 for i in a:
4 print(i)
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 9/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
8
90
12
78
1 #
2 a=[56,34,56,78] #list variable - allows duplicate values, stores data in natural ordering
3 b={56,34,56,78} #set variable, does not allows duplicates, used for searhing as it searche
4 c=(56,34,56,78) #tuple - it is like list but it is read-only collection
5 print("List is ",a)
6 print("Set is ",b)
7 #print(44 in b)
8 a.append(100)
9 b.add(100)
10 print(a)
11 print(b)
12 a.insert(2,200)
13 print(a)
14 a.pop(0)
15 print(a)
16 b.remove(56)
17 print(b)
18
19
20
21
1 a=[12,45,66,88,99,100,200]
2 print(a[1:-6:])
3
[]
1 stu={"rollno" : 240023,
2 "name" : "Jigar Shah",
3 "age" : 21
4 }
5 print(stu)
6 print(stu["rollno"])
7 print(stu["name"])
8 print(stu["age"])
9
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 10/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
1 stu={"rollno" : 240023,
2 "name" : "Jigar Shah",
3 "age" : 21
4 }
5
6 for k in stu.keys():
7 print(k,"----",stu[k])
8
9 for v in stu.values():
10 print(v)
11
12 for k,v in stu.items():
13 print(k,"----",v)
14
15
A 2D line plot in matplotlib is a graphical representation of data points connected by straight lines on a two-dimensional coordinate
system. It is a basic type of plot used to visualize the relationship between two continuous variables.
1 import pandas as pd #to read data from Excel or any tabular structure
2 import numpy as np #to modify pandas data at lower level
3 import matplotlib.pyplot as plt #to draw charts #pip install matplotlib
4 import seaborn as sns #to draw charts #pip install seaborn
5
6 year=[2015,2016,2017,2018,2019,2020]
7 price=[48000, 54000, 57000, 49000, 47000, 45000]
8 plt.plot(year, price)#by default always draws line chart
9 plt.grid()
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 11/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 12/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
Year Rohit Kohli
0 2008 404 165
1 2009 362 246
2 2010 404 307
3 2011 372 557
4 2012 433 364
5 2013 538 639
6 2014 390 359
7 2015 482 505
8 2016 489 973
9 2017 333 308
<ipython-input-11-f847abf446b1>:20: UserWarning: No artists with labels found to put in legend. Note that artists who
plt.legend()
<ipython-input-11-f847abf446b1>:24: UserWarning: No artists with labels found to put in legend. Note that artists who
plt.legend()
Scatter Plot
A scatter plot in matplotlib is a type of plot used to visualize the relationship between two continuous variables. It displays
individual data points as markers on a two-dimensional coordinate system, with one variable represented on the x-axis and the
other variable represented on the y-axis.
Bivariate Analysis
Numerical Vs Numerical
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 13/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
14 # Add axis labels
15 plt.xlabel("Years")
16 plt.ylabel("Runs Scored")
17 plt.grid()
18 plt.legend()
19 plt.show()
20 sns.scatterplot(x = "Year", y = "Kohli", data=df)
21 plt.ylabel("Runs Scored")
22 plt.show()
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 14/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
8 filepath=r"/content/drive/My Drive/Colab Notebooks/dsdata.xlsx"
9 df = pd.read_excel(filepath,"cricket2")
10 #print(df)
11 df.plot(kind="bar")
12 plt.title("IPL Indian Batsman")
13 # Add axis labels
14 plt.xlabel("Years")
15 plt.ylabel("Runs Scored")
16 plt.grid()
17 plt.legend()
18 plt.show()
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
from google.colab import drive import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns
plt.pie(df["Price"], labels=df["Object"])
df.plot(kind="pie",y="Price",labels=df["Product"])
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 15/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
11 ## plotting a pie chart
12 #plt.pie(df["Price"], labels=df["Object"])
13
14 df.plot(kind="pie",y="Price",labels=df["Product"])
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
Product Price
0 Bulb 45
1 Lamp 38
2 Table 120
3 Pen 20
4 Notebook 60
<Axes: ylabel='Price'>
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 16/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
32 #print(yesnocount)
33 # print("no. of yes is ",yesnocount["No"])
34 #if (yesnocount["Yes"]>yesnocount["No"]):
35 # df=df.fillna({"Purchased":"Yes"})
36 #else:
37 # df=df.fillna({"Purchased":"No"})
38 #print(df)
39
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
Country Age Salary Purchased
0 France 44.0 72000.0 No
1 Spain NaN NaN Yes
2 Germany 34.0 56000.0 No
3 Spain 38.0 61000.0 NaN
4 Germany NaN 47000.0 Yes
5 France 35.0 NaN Yes
6 Spain 56.0 80000.0 No
7 France 41.0 79000.0 NaN
8 Germany NaN NaN Yes
9 France 37.0 67000.0 Yes
Country Age Salary Purchased
0 France 44.0 72000.0 No
1 Spain 34.0 56000.0 Yes
2 Germany 34.0 56000.0 No
3 Spain 38.0 61000.0 Yes
4 Germany 35.0 47000.0 Yes
5 France 35.0 80000.0 Yes
6 Spain 56.0 80000.0 No
7 France 41.0 79000.0 Yes
8 Germany 37.0 67000.0 Yes
9 France 37.0 67000.0 Yes
Purchased
Yes 5
No 3
Name: count, dtype: int64
<ipython-input-35-0fdff979299c>:20: FutureWarning: DataFrame.fillna with 'method' is deprecated and will raise in a fu
df=df.fillna(method='bfill')
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remo
Experience Salary
0 1.0 10000
1 1.3 12000
2 1.4 12500
3 1.8 13800
4 2.0 14000
5 2.3 13990
6 2.6 14000
7 2.9 15000
8 3.0 15675
9 3.1 15899
10 3.2 17900
11 3.6 16900
12 3.8 18700
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 17/20
4/16/25, 8:12 AM ufpdsMAR2025_1.ipynb - Colab
13 3.9 20400
14 4.0 27900
15 4.1 30300
16 4.5 32900
17 4.8 34800
18 4.9 37900
19 5.0 40000
20 5.2 41000
21 5.5 45800
22 5.8 46800
23 5.9 39000
24 6.0 48900
25 6.1 50000
26 6.2 51000
27 6.3 51800
28 6.6 59000
Experience Salary z_score_salary
1 1.3 12000 -1.137602
2 1.4 12500 -1.104602
3 1.8 13800 -1.018804
4 2.0 14000 -1.005604
5 2.3 13990 -1.006264
6 2.6 14000 -1.005604
7 2.9 15000 -0.939605
8 3.0 15675 -0.895056
9 3.1 15899 -0.880272
10 3.2 17900 -0.748208
11 3.6 16900 -0.814207
12 3.8 18700 -0.695409
13 3.9 20400 -0.583211
14 4.0 27900 -0.088220
15 4.1 30300 0.070177
16 4.5 32900 0.241774
17 4.8 34800 0.367172
18 4.9 37900 0.571768
19 5.0 40000 0.710366
20 5.2 41000 0.776365
21 5.5 45800 1.093159
22 5.8 46800 1.159158
23 5.9 39000 0.644367
https://colab.research.google.com/drive/13Q7y3Nxsz6kICY24woquTpxwpwKTIY4L#scrollTo=Kpk4qXOQ3x9f&printMode=true 20/20