0% found this document useful (0 votes)
111 views

IP Practical Record 2022-23

The document contains details of a student named Anurag Mondal including their class, roll number, school and a list of 15 programming activities completed as part of their Informatics Practices practical exam. For each activity, the date and aim of the program is provided. The programs involve creating and manipulating series, dataframes and plotting charts in Python.

Uploaded by

Anurag Mondal
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)
111 views

IP Practical Record 2022-23

The document contains details of a student named Anurag Mondal including their class, roll number, school and a list of 15 programming activities completed as part of their Informatics Practices practical exam. For each activity, the date and aim of the program is provided. The programs involve creating and manipulating series, dataframes and plotting charts in Python.

Uploaded by

Anurag Mondal
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/ 43

NAME: ANURAG MONDAL

CLASS: XII-C
CBSE ROLL NO:
SCHOOL: Kendriya Vidyalaya Cossipore
Subject: INFORMATICS PRACTICES (065) Practical Record

1
INDEX
Sl. No. Program Sign. Of
Date
Teacher

Write a program in python to calculate the cube of the series


1 05-04-22
values as given below 2,5,7,4,9

Write a program in python to create a series Ser1 of numeric


data with labels as a, b, c, d, e. Then create a new series object
2 12-04-22
Ser2, contains squares of each values from Ser1. Display Ser2
values which are greater than 15.

3 19-04-22 Write a program in python to update aseries by writing code

Write a program in python to create series objects and display the


4 26-04-22
various attributes

Write a program in python to create a dataframe and display various


5 05-05-22
rows and columns

Write a program in python to perform various arithmetic operations


6 11-05-22
on dataframe

7 05-07-22 Write a program to create a dataframe and display the data using loc

Write a program to create a dataframe and display the data using


8 12-07-22
filtering and slicing

Write a program to create a dataframe and display the data using


9 27-07-22
iloc

Write a program to create a dataframe and add or remove rows or


10 03-08-22
columns

Write a Program to read CSV file and show its data in python using
11 10-08-22
dataFrames and pandas.

Write a Program to export the contents of following dataframe to a


12 16-08-22
CSV file with a separator character @

Write a Program to export the contents of a dataframe to a CSV file


13 19-08-22 with a separator character @ along with the NaN values stored as
Unplanned and separator as $.

14 23-08-22 Write a Program to extract the contents of a dataframe row wise

15 30-08-22 Write a Program to extract the contents a dataframe column wise

Write a Program to store records of students of a class using Boolean


16 06-09-22 indexing where index of Girl student records is True and that of Boy
records is False. Subsequently extract rows containing Girls & Boys.

17 14-09-22 Write a program to create a line chart.

2
Write a program in python to plot a line graph of marks obtained in
18 27-09-22
five subjects by five students

Write a program to plot a bar chart in python to display the result of


19 29-09-22
a school for five consecutive years.

20 14-10-22 Write a program to create the histogram for a given data

21 28-10-22 Write various MySQL queries

3
CERTIFICATE

This is to certify that this practical work in the


subject of Informatics Practices has been
done by Anurag Mondal of Class 12th– C for
the academic year 2022-23 for A.I.S.S.C.E.
Practical Examination conducted by
C.B.S.E. on
01-02-2023. The student has successfully
completed the practicals under guidance of
Mr. Arijit Ghosh as per the syllabus
prescribed by CBSE .

Signature of Internal Signature of External


Examiner Examiner

Principal’s
Signature

4
LAB ACTIVITY 1 Date:05-04-22

AIM: Write a program in python to calculate the cube of the series values as given below 2,5,7,4,9

#CODE
import pandas as pd #Importing pandas module
S_data = pd.Series([2,5,7,4,9]) #Creation of Series
#Printing of Original Series data
print("Original Series data")
print(S_data)
#Calculation and Printing of cubes of all data from new Series print("Cube of Series data")
Cube_data= S_data**3
print(Cube_data)

SAMPLE OUTPUT
Original Series data
02
15
27
34
49
dtype: int64
Cube of Series data
08
1 125
2 343
3 64
4 729
dtype: int64

5
LAB ACTIVITY 2 Date:12-04-22

AIM: Write a program in python to create a series Ser1 of numeric data with labels as a, b, c, d, e.
Then create a new series object Ser2, contains squares of each values from Ser1. Display Ser2
values which are greater than 15.

#CODE
import pandas as pd #Importing pandas module
Ser1 = pd.Series([2,3,5,4,1], index=['a','b','c','d','e']) #Creation of Series Ser1
#Printing of Original Series data
print("Series Ser1 data")
print(Ser1)
Ser2= Ser1**2 #Calculation the square of Ser1 and stored in Ser1
print(Ser2[Ser2>15]) #Checking the values which are greater than 15 and printing

SAMPLE OUTPUT
Series Ser1 data
a2
b3
c5
d4
e1
dtype: int64
c 25
d 16
dtype: int64

6
LAB ACTIVITY 3 Date:19-04-22

AIM: Write a program in python to update the following series by writing code for question (i) to
(v)
Kiran 33
Manvendra 48
Saswati NaN
Yash 43
(i) Create the above Series Ser
(ii) Add a new student Dev with marks 40
(iii) Fill all missing values by 0.
(iv) Update marks of Manvendra and Saswati by 44.
(v) Display all information of Yash and Manvendra. (First display Yash then Manvendra)

#CODE

import pandas as pd
import numpy as np

# Creation of Series object Ser


data = [33, 48, np.NaN, 43]
Ser = pd.Series(data, index=['Kiran','Manvendra', 'Saswati', 'Yash'])
print(" Output (i)\n===================\n",Ser)

# Adding a new student Dev with marks 40


Ser['Dev']=40
print("\n Output (ii)\n===================\n",Ser)

# filling of missing values as 0


Ser.fillna(0, inplace=True)
print("\n Output (iii)\n===================\n",Ser)

# Updation of marks for Manvendra and Saswati by 44


Ser[1:3]=44
print("\n Output (iv)\n===================\n",Ser)

# Display of marks for Yash and Manvendra


print("\n Output (v)\n===================\n",Ser[['Yash','Manvendra']])

7
SAMPLE OUTPUT
Output (i)
===================
Kiran 33.0
Manvendra 48.0
Saswati NaN
Yash 43.0
dtype: float64

Output (ii)
===================
Kiran 33.0
Manvendra 48.0
Saswati NaN
Yash 43.0
Dev 40.0
dtype: float64

Output (iii)
===================
Kiran 33.0
Manvendra 48.0
Saswati 0.0
Yash 43.0
Dev 40.0
dtype: float64

Output (iv)
===================
Kiran 33.0
Manvendra 44.0
Saswati 44.0
Yash 43.0
Dev 40.0
dtype: float64

Output (v)
===================
Yash 43.0
8
Manvendra 44.0
dtype: float64

LAB ACTIVITY 4 Date:26-04-22

AIM: Write a program in python to create two series objects Obj1 and Obj2 (data given below) and
display the following attributes in the format given below.
Structure of Series objects Output format
Obj1 Obj2
A 6700 A 640
B 5600 B 720
C 5000 C 1020
D 5200 D 437
E nil

Attribute Name Object 1 Object 2


Data Type
Shape
No. of Bytes
No. of Dimensions
Item Size
Has Nans?
Empty

#CODE
import pandas as pd
import numpy as np
Obj1 = pd.Series([6700,5600,5000,5200,np.NaN], index=['A', 'B', 'C', 'D', 'E'])
Obj2 = pd.Series([640,720,1020,437], index=['A', 'B', 'C', 'D'])
print("Attribute Name\t\tObject 1\t\tObject 2")
print("_______________________________________________________")
print("Data Type\t\t", Obj1.dtype, "\t\t", Obj2.dtype)
print("Shape \t\t", Obj1.shape, "\t\t\t", Obj2.shape)
print("No. of Bytes\t\t", Obj1.nbytes, "\t\t\t", Obj2.nbytes)
print("No. of Dimensions\t",Obj1.ndim,"\t\t\t",Obj2.ndim)
print("Item Size \t",Obj1.size,"\t\t\t",Obj2.size)
print("Has Nans? \t\t",Obj1.hasnans,"\t\t\t",Obj2.hasnans)
print("Empty \t",Obj1.empty,"\t\t\t",Obj2.empty)

SAMPLE OUTPUT
Attribute Name Object 1 Object 2
__________________________________________________________________________
Data Type float64 int64
Shape (5,) (4,)

9
No. of Bytes 40 32
No. of Dimensions 1 1
Item Size 5 4
Has Nans? True False
Empty False False
LAB ACTIVITY 5 Date:05-05-22
AIM: Write a program in python to create a dataframe fruits from following data and answer the
questions (i) to (v)-
Color Count Price
Orange Yellow 30 40
Orange Green 19 30
Mango Yellow 25 60
Mango Green 29 120
Pear Green 65 150
(i) Add a new column ‘Variety’ contains data as ‘Normal’, ‘Normal’, ‘Dashari’, ‘Hafooj’, ‘Normal’
(ii) Add a new row ‘Apple’ containing Red, 40,190, Kashmiri.
(iii) Display price of all fruits.
(iv) Display color and price of all fruits.
(v) Display all columns from count to variety.

#CODE
import pandas as pd
d=
{'Color':['Yellow','Green','Yellow','Green','Green'],'Count':[30,19,25,29,65],'Price':[40,30,60,120,150
]}
fruits=pd.DataFrame(d,index=['Orange','Orange','Mango','Mango','Pear'])
print("Original Dataframe\n===================\n",fruits)

#Adding a new column Variety


fruits['Variety']=['Normal', 'Normal', 'Dashari', 'Hafooj', 'Normal']
print("Output (i)\n===================\n",fruits)

#Adding a new row Apple


fruits.loc['Apple']=['Red',40,190,'Kashmiri']
print("Output (ii)\n===================\n",fruits)

#Display price of all fruits


print("Output (iii)\n===================\n",fruits['Price'])

#Display color and price of all fruits


print("Output (iv)\n===================\n",fruits[['Color','Price']])

#Display count to variety all columns


print("Output (v)\n===================\n",fruits.loc[:,'Count':'Variety'])
10
SAMPLE OUTPUT
Original Dataframe
===================
Color Count Price
Orange Yellow 30 40
Orange Green 19 30
Mango Yellow 25 60
Mango Green 29 120
Pear Green 65 150

Output (i)
============================================
Color Count Price Variety
Orange Yellow 30 40 Normal
Orange Green 19 30 Normal
Mango Yellow 25 60 Dashari
Mango Green 29 120 Hafooj
Pear Green 65 150 Normal

Output (ii)
============================================
Color Count Price Variety
Orange Yellow 30 40 Normal
Orange Green 19 30 Normal
Mango Yellow 25 60 Dashari
Mango Green 29 120 Hafooj
Pear Green 65 150 Normal
Apple Red 40 190 Kashmiri

Output (iii)
===================
Orange 40
Orange 30
Mango 60
Mango 120
Pear 150
Apple 190
Name: Price, dtype: int64

11
Output (iv)
=============================
Color Price
Orange Yellow 40
Orange Green 30
Mango Yellow 60
Mango Green 120
Pear Green 150
Apple Red 190

Output (v)
==============================
Count Price Variety
Orange 30 40 Normal
Orange 19 30 Normal
Mango 25 60 Dashari
Mango 29 120 Hafooj
Pear 65 150 Normal
Apple 40 190 Kashmiri

12
LAB ACTIVITY 6 Date: 11-05-22

AIM Write a program in python to perform following arithmetic operations on dataframe. df1 df2
df1 df2
0 1 2 0 1 2
0 3 4 5.0 0 2.0 8.0 3
1 2 7 NaN 1 NaN 5.0 5
2 3 2 1.0 2 NaN NaN 2

#CODE
import pandas as pd
import numpy as np
#Creation of dataframe df1
df1 = pd.DataFrame([[3,4,5],[2,7,np.NaN],[3,2,1]])

#Creation of dataframe df2


df2 = pd.DataFrame([[2,8,3],[np.NaN,5,5],[np.NaN,np.NaN,2]])

#Addition of two dataframe


df3=df1+df2
# df3 = df1.add(df2)
print("Output (ii)\n===================\n df1+df2\n",df3)

# Subtraction of df2 from df1


df4=df1-df2
# df4 = df1.sub(df2) , df4 = df2.rsub(df1)
print("Output (ii)\n===================\n df1 - df2\n",df4)

#Multiplication of two dataframe


df5=df1*df2
#df5 = df1.mul(df2)
print("Output (iii)\n===================\n df1 X df2\n",df5)

#Division operation in two dataframe


df6=df1/df2
# df6 = df1.div(df2) , df6 = df2.rdiv(df1)
print("Output (iv)\n===================\n df1/df2\n",df6)

#Scaler arithmetic’s
df7=df1 + 10
13
print("Output (v)\n===================\n df1 + 10\n",df7)
SAMPLE OUTPUT
Output (ii)
===================
df1+df2
0 1 2
0 5.0 12.0 8.0
1 NaN 12.0 NaN
2 NaN NaN 3.0

Output (ii)
===================
df1 - df2
0 1 2
0 1.0 -4.0 2.0
1 NaN 2.0 NaN
2 NaN NaN -1.0

Output (iii)
===================
df1 X df2
0 1 2
0 6.0 32.0 15.0
1 NaN 35.0 NaN
2 NaN NaN 2.0

Output (iv)
===================
df1/df2
0 1 2
0 1.5 0.5 1.666667
1 NaN 1.4 NaN
2 NaN NaN 0.500000

Output (v)
===================
df1 + 10
0 1 2
0 13 14 15.0
1 12 17 NaN
2 13 12 11.0

14
LAB ACTIVITY 7 Date: 11-05-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df

(i) Display number of masks bought by SMS.


(ii) Display amount paid by various hospitals.
(iii) Display amount paid by AIIMS and SMS in same sequence.
(iv) Display masks bought by Fortis
(v) Display all details of Fortis hospital.

#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) Display number of masks bought by SMS.
print("\nMasks bought by SMS = ",Covid_df.Masks['SMS'])

#(ii)Display amount paid by all hospitals.


print("\nAmount paid by all hospitals\n", Covid_df['Amount'])

#(iii) Display amount paid by AIIMS and SMS in same sequence.


print("\nAmount paid by SMS and AIIMS\n", Covid_df.loc[['AIIMS','SMS'],['Amount']])

#(iv) Display masks bought by Fortis


print("\nMasks bought by Fortis Hospital = ", Covid_df['Masks']['FORTIS'])

#(v) Display all details of Fortis hospital.


print("\nFortis Hospital =\n ", Covid_df.loc['FORTIS'])

SAMPLE OUTPUT
Masks bought by SMS = 30000

Amount paid by all hospitals

15
SMS 2700000
AIIMS 4200000
SDMH 20000
FORTIS 150000
SDMH 2500000
Name: Amount, dtype: int64
Amount paid by SMS and AIIMS
Amount
AIIMS 4200000
SMS 2700000

Masks bought by Fortis Hospital = 15000

Fortis Hospital =
Masks 15000
Gloves 5000
Amount 150000
Name: FORTIS, dtype: int64

16
LAB ACTIVITY 8 Date: 12-07-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df

(i) Display total gloves bought by AIIMS using index only.


(ii) Find all rows with label ‘SDMH’ with all columns.
(iii) Find hospital paid amount more than 200000.
(iv) List single True or False to signify if all amount more than 200000 or not.
(v) List 2nd , 3rd and 4th rows.

#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])

#(i) Display total gloves bought by AIIMS using index only.


print("\n",Covid_df.iloc[1:2,1:2]) # Covid_df.iloc[1,1]

#(ii) Find all rows with label ‘SDMH’ with all columns.
print("\n",Covid_df.loc['SDMH',:]) # Covid_df.loc['SDMH']

#(iii) Find hospital paid amount more than 200000.


print("\n",Covid_df[Covid_df['Amount']>200000])

#(iv) List single True or False to signify if all amount more than 200000 or not.
print("\nChecking if all row contains amount greater than 200000 =
",(Covid_df['Amount']>200000).all())

#(v) List 2nd , 3rd and 4th rows.


print("\n",Covid_df.iloc[1:4,:])

SAMPLE OUTPUT
17
Gloves
AIIMS 1500000

Masks Gloves Amount


SDMH 10000 500000 20000
SDMH 35000 30000 2500000

Masks Gloves Amount


SMS 30000 80000 2700000
AIIMS 50000 1500000 4200000
SDMH 35000 30000 2500000

Checking if all row contains amount greater than 200000 = False

Masks Gloves Amount


AIIMS 50000 500000 4200000
SDMH 10000 500000 20000
FORTIS 15000 5000 150000

18
LAB ACTIVITY 9 Date: 27-07-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df

(i) Display number of masks bought by SMS.


(i) List only the columns Masks and Amount.
(ii) List columns 0 to 1 .
(iii) List only rows with labels AIIMS and FORTIS
(iv) List only rows 0, 2, 3
(v) Display data of rows AIIMS, SDMH and columns Masks and Gloves

#CODE

import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) List only the columns Masks and Amount.
print("\n",Covid_df[['Masks','Amount']])

#(ii) List columns 0 to 1.


print("\n",Covid_df.iloc[:, 0:2])

#(iii) List only rows with labels AIIMS and FORTIS


print("\n",Covid_df.loc[['AIIMS','FORTIS']])

#(iv) List only rows 0,2,3


print("\n",Covid_df.iloc[[0,2,3]])

#(v) Display details of Masks and Gloves bought by AIIMS and SDMH
print("\n",Covid_df.loc[['AIIMS','SDMH'],['Masks','Gloves']])

19
SAMPLE OUTPUT
Masks Amount
SMS 30000 2700000
AIIMS 50000 4200000
SDMH 10000 20000
FORTIS 15000 150000
SDMH 35000 2500000

Masks Gloves
SMS 30000 80000
AIIMS 50000 1500000
SDMH 10000 500000
FORTIS 15000 5000
SDMH 35000 30000

Masks Gloves Amount


AIIMS 50000 1500000 4200000
FORTIS 15000 5000 150000

Masks Gloves Amount


SMS 30000 80000 2700000
SDMH 10000 500000 20000
FORTIS 15000 5000 150000

Masks Gloves
AIIMS 50000 1500000
SDMH 10000 500000
SDMH 35000 30000

20
LAB ACTIVITY 10 Date: 03-08-22
AIM Write a program to create a the following dataframe and answer the questions (i) to (v)-
Dataframe name : Covid_df

(i) Add new row as : SHALBY 5000 20000 150000


(ii) Add a column as Remarks with data -> Paid, Pending, Paid, Paid, Pending, Paid
(iii) Remove rows labelled as SMS and FORTIS.
(iv) Update remarks of AIIMS as Paid.
(v) Remove columns Amount and Remarks.

#CODE
import pandas as pd
dict = {'Masks': [30000,50000,10000,15000,35000],
'Gloves':[80000,1500000,500000,5000,30000],
'Amount':[2700000,4200000,20000,150000,2500000]}
Covid_df = pd.DataFrame(dict, index=['SMS','AIIMS','SDMH','FORTIS','SDMH'])
#(i) Add new row as SHALBY 5000 20000 150000
Covid_df.loc['SHALBY'] = [5000,20000,150000]
print("Output of (i)\n",Covid_df)

#(ii) Add a column as Remarks with data-->Paid, Pending,Paid, Paid,Pending,Paid


Covid_df['Remarks'] = ['Paid','Pending','Paid','Paid','Pending','Paid']
print("\nOutput of (ii)\n",Covid_df)

#(iii) Remove rows with label SMS and FORTIS.


Covid_df.drop(['SMS','FORTIS'], inplace=True)
print("\nOutput of (iii)\n",Covid_df)

#(iv) Update remarks of AIIMS as Paid.


Covid_df.loc['AIIMS','Remarks']='Paid' #Covid_df.at['AIIMS','Remarks']='Paid'
print("\nOutput of (iv)\n",Covid_df)

#(v) Remove columns Amount and Remarks.


Covid_df.drop(['Amount','Remarks'],axis=1, inplace=True)
print("\nOutput of (v)\n",Covid_df)

21
SAMPLE OUTPUT

Output of (i)
Masks Gloves Amount
SMS 30000 80000 2700000
AIIMS 50000 1500000 4200000
SDMH 10000 500000 20000
FORTIS 15000 5000 150000
SDMH 35000 30000 2500000
SHALBY 5000 20000 150000

Output of (ii)
Masks Gloves Amount Remarks
SMS 30000 80000 2700000 Paid
AIIMS 50000 1500000 4200000 Pending
SDMH 10000 500000 20000 Paid
FORTIS 15000 5000 150000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid

Output of (iii)
Masks Gloves Amount Remarks
AIIMS 50000 1500000 4200000 Pending
SDMH 10000 500000 20000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid

Output of (iv)
Masks Gloves Amount Remarks
AIIMS 50000 1500000 4200000 Paid
SDMH 10000 500000 20000 Paid
SDMH 35000 30000 2500000 Pending
SHALBY 5000 20000 150000 Paid

Output of (v)
Masks Gloves
AIIMS 50000 1500000
SDMH 10000 500000
SDMH 35000 30000
SHALBY 5000 20000
22
LAB ACTIVITY 11 Date: 10-08-22
AIM Write a Program to read CSV file and show its data in python using dataFrames and pandas.
#CODE
import pandas as pd
df=pd.read_csv("d://students.csv", nrows=3)
print("To display selected number of rows from beginning")
print(df)

print("\nDataframe formed by skipping first 2 rows")


df=pd.read_csv("d://students.csv",skiprows=2,header=None)
print(df)

print("\nUsing a column of csv as index")


df=pd.read_csv("d://students.csv",index_col='Name')
print(df)

SAMPLE OUTPUT
To display selected number of rows from beginning
Name Marks Class Section
0 Megha 65 12 C
1 Rachit 73 11 B
2 Neeraj 45 11 C

Dataframe formed by skipping first 2 rows


0 1 2 3
0 Rachit 73 11 B
1 Neeraj 45 11 C
2 Tanmay 66 12 D
3 Ali 85 11 A
4 Muskaan 78 12 A

Using a column of csv as index


Marks Class Section
Name
Megha 65 12 C
Rachit 73 11 B
Neeraj 45 11 C
Tanmay 66 12 D
Ali 85 11 A
Muskaan 78 12 A

23
LAB ACTIVITY 12 Date: 16-08-22
AIM Write a Program to export the contents of following dataframe to a CSV file with a separator
character @.

#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
shop_df.to_csv("d:\\shop.csv",sep='@')

SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN

Contents of shop.csv
@Name@Product@Target@Sales
A@East@Oven@56000.0@58000.0
B@West@AC@70000.0@68000.0
C@Central@AC@75000.0@78000.0
D@South@Oven@60000.0@61000.0
E@North@TV@@
F@Rural@Music Player@@

24
LAB ACTIVITY 13 Date: 19-08-22
AIM Write a Program to export the contents of following dataframe to a CSV file with a separator
character @ along with the NaN values stored as Unplanned and separator as $.

#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
shop_df.to_csv("d:\\shop.csv",sep='$',na_rep=’Unplanned’)

SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN

Contents of shop.csv
$Name$Product$Target$Sales
A$East$Oven$56000.0$58000.0
B$West$AC$70000.0$68000.0
C$Central$AC$75000.0$78000.0
D$South$Oven$60000.0$61000.0
E$North$TV$Unplanned$Unplanned
F$Rural$Music Player$Unplanned$Unplanned

25
LAB ACTIVITY 14 Date: 27-08-22
AIM Write a Program to extract the contents of following dataframe row wise

#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)
for (row, rowSeries) in shop_df.iterrows():
print(“Row index:”,row)
print(“Containing:”)
print(rowSeries)

SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN

Row index: A
Containing:
===================
Name East
Product Oven
Target 56000
Sales 58000
Name: A, dtype: object

Row index: B
Containing:
===================
Name West
Product AC
Target 70000
26
Sales 68000
Name: B, dtype: object

Row index: C
Containing:
===================
Name Central
Product AC
Target 75000
Sales 78000
Name: C, dtype: object

Row index: D
Containing:
===================
Name South
Product Oven
Target 60000
Sales 61000
Name: D, dtype: object

Row index: E
Containing:
===================
Name North
Product TV
Target NaN
Sales NaN
Name: E, dtype: object

Row index: F
Containing:
===================
Name Rural
Product Music Player
Target NaN
Sales NaN
Name: F, dtype: object

27
LAB ACTIVITY 15 Date: 30-08-22
AIM Write a Program to extract the contents of following dataframe column wise

#CODE
import pandas as pd
import numpy as np
shop={'Name':['East','West','Central','South','North','Rural'],\
'Product':['Oven','AC','AC','Oven','TV','Music Player'],\
'Target':[56000,70000,75000,60000,np.NaN,np.NaN],\
'Sales':[58000,68000,78000,61000,np.NaN,np.NaN]}
shop_df=pd.DataFrame(shop,index=['A','B','C','D','E','F'])
print(shop_df)

for (col, colSeries) in shop_df.iteritems():


print("\nColumn",col,"Containing:\n======================================\n")
print(colSeries)

SAMPLE OUTPUT
Name Product Target Sales
A East Oven 56000.0 58000.0
B West AC 70000.0 68000.0
C Central AC 75000.0 78000.0
D South Oven 60000.0 61000.0
E North TV NaN NaN
F Rural Music Player NaN NaN

Column Name Containing:


======================================
A East
B West
C Central
D South
E North
F Rural
Name: Name, dtype: object

Column Product Containing:


======================================
A Oven
B AC
C AC
D Oven
28
E TV
F Music Player
Name: Product, dtype: object

Column Target Containing:


======================================
A 56000.0
B 70000.0
C 75000.0
D 60000.0
E NaN
F NaN
Name: Target, dtype: float64

Column Sales Containing:


======================================
A 58000.0
B 68000.0
C 78000.0
D 61000.0
E NaN
F NaN
Name: Sales, dtype: float64

29
LAB ACTIVITY 16 Date: 30-08-22
AIM Write a Program to store records of students of a class using Boolean indexing where index
of Girl student records is True and that of Boy records is False. Subsequently extract rows
containing Girls & Boys.

#CODE
import pandas as pd
stu_marks=[[1,'AHAM KUMAR KHARA',42],\
[5,'DARSHANA SHAH',47],\
[8,'SAMIR PRUSTY',44],\
[11,'ABHIJIT DEY',42],\
[12,'SALONI SINGH',47],\
[19,'PRIYANKA ROY',42],\
[28,'KRISTINA WILLIAMS',49]]
marks_df=pd.DataFrame(stu_marks,columns=['ROLL
NO','NAME','IP'],index=[False,True,False,False,True,True,True])
print("\nMarks of Students in IP\n============================================")
print(marks_df)
print("\nMarks of Girls in IP\n============================================")
print(marks_df.loc[True])
print("\nMarks of Boys in IP\n=============================================")
print(marks_df.loc[False])

SAMPLE OUTPUT
Marks of Students in IP
==================================================
ROLL NO NAME IP
False 1 AHAM KUMAR KHARA 42
True 5 DARSHANA SHAH 47
False 8 SAMIR PRUSTY 44
False 11 ABHIJIT DEY 42
True 12 SALONI SINGH 47
True 19 PRIYANKA ROY 42
True 28 KRISTINA WILLIAMS 49

Marks of Girls in IP
==================================================
ROLL NO NAME IP
True 5 DARSHANA SHAH 47
True 12 SALONI SINGH 47
True 19 PRIYANKA ROY 42
True 28 KRISTINA WILLIAMS 49

30
Marks of Boys in IP
==================================================
ROLL NO NAME IP
False 1 AHAM KUMAR KHARA 42
False 8 SAMIR PRUSTY 44
False 11 ABHIJIT DEY 42

31
LAB ACTIVITY 17 Date: 14-09-22

AIM: Write a program to create a line chart for following data


cls=['I','II','III','IV','V']]
students=[43,37,39,33,34]

Write code to
(a) Display dashed line
(b) Display + (plus) marker
(c )Change the marker color to blue

#CODE
import matplotlib.pyplot as plt
cls=['I','II','III','IV','V']
students=[43,37,39,33,34]
plt.plot(cls,students,color='r',linestyle='dashed',marker='+',markeredgecolor='b')
plt.xlabel("CLASS")
plt.ylim(30,45)
plt.ylabel("No of Students")
plt.title("Enrollment of a School")
plt.show()plt.show()

SAMPLE OUTPUT

32
LAB ACTIVITY 18 Date: 27-09-22

AIM Write a program in python to plot a line graph of marks obtained in five subjects by five
students st

#CODE
import matplotlib.pyplot as plt
student=['Amit',"Bhavesh",'Chetan','Dhirubhai','Ehsan']
std1=[12,66,32,42,33]
std2=[32,55,64,76,98]
std3=[34,9,76,86,33]
std4=[34,66,23,43,17]
std5=[45,75,22,45,73]
plt.plot(student,std1,marker='s',markersize='5',label='Chemistry')
plt.plot(student,std2,marker='s',markersize='5',label='Computer Science')
plt.plot(student,std3,marker='s',markersize='5',label='English')
plt.plot(student,std4,marker='s',markersize='5',label='Maths')
plt.plot(student,std5,marker='s',markersize='5',label=' Physics ')
plt.xlabel('Student Name')
plt.ylabel('Marks of various Subjects')
plt.legend(loc='upper left')
plt.show()

SAMPLE OUTPUT

33
LAB ACTIVITY 19 Date: 29-09-22
AIM: Write a program to plot a bar chart in python to display the result of a school for five
consecutive years.
(a) Change the colour bars in sequence as red, yellow, green, blue, cyan
(b) Change width of bars in sequence as 0.5,0.6,0.7,0.8,0.9
#CODE

#Importing modules for matplotlib.pyplot


import matplotlib.pyplot as plt
Years=[2014,2015,2016,2017,2018]
PerResult=[91.0,89.7,84.2,98.9,94.3]
clr=['r','y','g','b','c']
wd=[0.5,0.6,0.7,0.8,0.9]
plt.bar(Years,PerResult,color=clr,width=wd)
plt.xlabel("Years")
plt.ylabel("Result in percentage")
plt.show()

SAMPLE OUTPUT

34
LAB ACTIVITY 20 Date: 14-10-22

AIM Write a program to create the histogram for the data is given below.
Weight measurements for 16 small orders of French Fries (in grams).
78, 72, 69, 81, 63, 67, 65, 73, 79, 74, 71, 83, 71, 79, 80, 69
(a) Create a simple histogram from above data.
(b) Create a horizontal histogram from above data.
(c) Create a step type of histogram from above data.
(d) Create a cumulative histogram from above data.
#CODE
import numpy as np
import matplotlib.pyplot as plt
wff=np.array([78,72,69,81,63,67,65,75,79,74,71,83,71,79,80,69]) #weight of French fries
"""(a) Create a simple histogram from above data."""
plt.hist(wff)
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Normal Histogram")
plt.show()
35
"""(b) Create a horizontal histogram from above data."""
plt.hist(wff, orientation='horizontal')
plt.xlabel("Frequency")
plt.ylabel("Weight of French fries")
plt.title("Horizontal Histogram")
plt.show()
"""(c) Create a step type of histogram from above data."""
plt.hist(wff,histtype='step')
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Step Type Histogram")
plt.show()
"""(d) Create a cumulative histogram from above data."""
plt.hist(wff,cumulative=True)
plt.xlabel("Weight of French fries")
plt.ylabel("Frequency")
plt.title("Cumulative Histogram")
plt.show()

SAMPLE OUTPUT (a)

36
SAMPLE OUTPUT (b)

SAMPLE OUTPUT (c)

37
SAMPLE OUTPUT (d)

LAB ACTIVITY 21 Date: 28-10-22

38
AIM Write various MySQL queries.
• Create a database kvc.
• Inside the database create table emp.
• Insert the data as per shown in the screenshot.

Write Queries for the followings:-

1. Write a query to display all contents of table employee table.


Ans. SELECT * FROM emp;

2. Write a query to display different jobs from employee table.

39
Ans. SELECT distinct(job) FROM emp;

3. Write a query to display the empname who is earning more than 2500.
Ans. SELECT ename FROM emp WHERE sal>2500;

4. Write a query to display the managers working in department number 10. Ans.
Ans. SELECT ename , job, deptno FROM emp WHERE JOB=’MANAGER’ and deptno=10;

5. Write a query to display the name of employee joined on or after 01-MAY-1981.


Ans. SELECT ename, hiredate FROM emp WHERE hiredate>='1981-05-01';

BLAKE

6. Write a query to display the managers who earn more than 2800.

40
Ans. SELECT ename, job, sal FROM emp WHERE job='MANAGER' AND sal>2800;

7. Write a query to display the department number where more than three employees are
working.
Ans. SELECT deptno, count(*) as ‘No of Employees’ FROM emp GROUP BY deptno HAVING
count(*)>3;

8. Write a query to display the name of employee with their salary in order of their joining.
Ans. SELECT ename, sal, hiredate FROM emp ORDER BY hiredate;

9. Write a query to display the name and salary from department number 30 and sorted in
descending order of salary.
Ans. SELECT ename, deptno, sal FROM emp WHERE deptno=30 ORDER BY sal DESC;

10. Write a query to display maximum salary paid in each deptno.


41
Ans. SELECT deptno, max(sal) FROM emp GROUP BY deptno;

11. Write a SQL command to increase the salary by 300 to the employees belong to deptno 20.
Ans. UPDATE emp SET sal=sal+300 WHERE deptno=20;

12. Insert the following data in table employee


8000,'DEVESH','CLERK',7200,'01-JAN-2011',3500,0,10
Ans. INSERT INTO emp VALUES (8000,'DEVESH','CLERK',7200,'2011-01-01',3500,0,10);

13. Write a query to display the employee name earning between 1500 and 2500.
42
Ans.
Method-1 SELECT ename, sal FROM emp WHERE sal>=1500 AND sal<=2500;
Method-2 SELECT ename, sal FROM emp WHERE sal BETWEEN (1500 and 2500);

14. Write a query to display the employee name joined in the year 1981.
Ans.
Method-1 SELECT ename, hiredate FROM emp WHERE hiredate>='1981-01-01' AND
hiredate<='1981-12-31';
Method-2 SELECT ename, hiredate FROM emp WHERE hiredate between ("'1981-01-01"
and "'1981-12-31");
Method-3 SELECT ename, hiredate FROM emp WHERE year(hiredate)=1981;

15. Write a query to display details of employees getting some commission.


Ans. SELECT * FROM emp WHERE comm IS NOT NULL and comm <> 0;

16. Write a query to see average salary paid to department number 20.
Ans. SELECT deptno, AVG(sal) FROM emp WHERE deptno=20;

43

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy