Jasmine Practical File IP
Jasmine Practical File IP
Jasmine Practical File IP
Practices
Jasmine Kaur Kohli
XII-D
x=input(“Enter an alphabet”)
if (x=='a' or x=='e' or x=='i' or x=='o' or x=='u'):
print("It is a vowel")
else:
print("Not a vowel")
Name and Age
a=int(input("Enter a number"))
for n in range(0,a):
print("Good Morning")
Table of a number
a=int(input("Enter a number"))
for n in range(1,11):
print (n*a)
Sum of numbers till “n”
sum=0
for n in range(1,11):
if n%2==0:
sum+=n
print(sum)
Sum of natural numbers from 1-5
sum=0
for n in range(1,6):
sum+=n
print(sum)
First 10 even numbers
for n in range(1,11):
print(n*2)
Odd/Even nos. up to a given no,
num=int(input("Enter a number"))
if num%2==0:
for n in range(2,num+1,2):
print(n)
elif num!=0:
for n in range(1, num+1,2):
print(n)
Greatest out of 3 numbers
a=int(input("Enter a number"))
b=int(input("Enter how many times you need the multiple"))
for i in range(1,b+1):
print (i*a)
Square of “n” numbers
n=int(input("Enter a no"))
for n in range (0,n+1):
print(n**2)
Factorial
str1="He is playing in the ground. She is the only player. The playing condition is good."
a=(str1.count("the"))
b=(str1.count("The"))
print("Count of The/the in text:",a+b)
Average of 5 marks
Festival=['Lumbini','Mopin','Bihu','Chhath','Onam','Lohri','Pongal','Garba']
a=input("Enter the name of a festival")
print(a in Festival)
Simple Interest
pi=3.14
r=int(input("Enter the radius"))
area=a=pi*r**2
circumference=c=2*pi*r
print("The area of the circle is",a,"and the circumference is",c)
Series from List
Import pandas as pd
Jasmine","Rachneet","Satvik","Japjot","Sarnav","Nidhi"]
s1=pd.Series(l1,index=[10,20,30,40,50,60])
s1.name="Names"
s1.index.name="id"
print(s1.head(2))
print(s1.tail(2))
print(s1)
print(s1[2:4])
print(s1.values)
print(s1.size)
print(s1.empty)
print(s1.count())
Series from Dictionary
import pandas as pd
d1={"Jasmine":1,"Rachneet":2,"Satvik":3,"Japjot":4,"Sarnav":5,"Nidhi":6}
s1=pd.Series(d1)
s1.name="Names"
s1.index.name="S.no"
print(s1)
print(s1.head(3))
print(s1.tail(2))
print(s1[2:5])
print(s1.size)
print(s1.count())
print(s1.empty)
print(s1.values)
print(s1["Rachneet":"Japjot"])
print(s1.get(2))
Operations on Series
length=10
breadth=20
A=length*breadth
print(“Area of the rectangle is “,A)
DataFrame from series
import pandas as pd
l1=[78,95]
s1=pd.Series(l1)
l2=[89,67]
s2=pd.Series(l2)
l3=[95,84]
s3=pd.Series(l3)
df1=pd.DataFrame({"Term1":s1,"Term2":s2,"Term3":s3})
print(df1)
df1["final"]=df1["Term1"]/4+df1["Term2"]/4+df1["Term3"]/2
print(df1)
Vowels Series
Q) Create a series Vowels, having 5 elements with index labels ‘a’,‘e’, ‘i’, ‘o’ and ‘u’ and all the five
values set to zero. Check if it is an empty series.
Vowels=pd.Series(0,index=['a','e','i','o','u'])
print(Vowels)
print(Vowels.empty)
Series with alphabets
Q) Create a series EngAlph, having 5 elements with first 5 alphabets as values and default index
values.
import pandas as pd
l1=['a','b','c','d','e']
EngAlph=pd.Series(l1)
print(EngAlph)
Friends Series
Q) Create a Series; Friends, from a dictionary having roll numbers of five of your friends as data and
their first name as keys.
import pandas as pd
f1={"Jasmine":15,"Rachneet":25,"Madhav":17,"Satvik":21,"Anika":20}
Friends=pd.Series(f1)
print(Friends)
MT Series
import pandas as pd
MTSeries=pd.Series()
print(MTSeries)
print(MTSeries.empty)
Dataframe from dictionary of lists
import pandas as pd
dict1={"n1":["Jasmine","Rachneet","Anika"],"a1":[16,15,17]}
df=pd.DataFrame(dict1)
df['Marks']=[35,34,21]
df.loc[4]=["Madhav",18,45]
print(df)
DataFrame from series
import pandas as pd
l1=[78,95]
s1=pd.Series(l1)
l2=[89,67]
s2=pd.Series(l2)
l3=[95,84]
s3=pd.Series(l3)
df1=pd.DataFrame({"Term1":s1,"Term2":s2,"Term3":s3})
print(df1)
df1["final"]=df1["Term1"]/4+df1["Term2"]/4+df1["Term3"]/2
print(df1)
DataFrame - Sales
Q) Create the following DataFrame Sales containing year wise sales figures for five sales persons in
INR. Use the years as column labels, and sales person names as row labels.
import pandas as pd
dict1={"2014":[100.5,150.8,200.9,30000,40000],"2015":[12000,18000,22000,30000,45000]}
Sales=pd.DataFrame((dict1),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
Sales["2016"]=[20000,50000,70000,100000,125000]
Sales["2017"]=[50000,60000,70000,80000,90000]
print(Sales)
print(Sales.index)
print(Sales.columns)
print(Sales.dtypes)
print(Sales.values)
print(Sales.shape)
print(Sales.size)
DataFrame – Sales (contd.)
import pandas as pd
dict1={"2014":[100.5,150.8,200.9,30000,40000],"2015":[12000,18000,22000,30000,45000]}
Sales=pd.DataFrame((dict1),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
Sales["2016"]=[20000,50000,70000,100000,125000]
Sales["2017"]=[50000,60000,70000,80000,90000]
print(Sales)
dict2={"2018":[160000,110000,500000,340000,900000]}
Sales2=pd.DataFrame((dict2),index=["Madhu","Kusum","Kinshuk","Ankit","Shruti"])
print(Sales2)
Sales=Sales.append(Sales2)
print(Sales)
print(Sales.T)
print(Sales.loc["Madhu","2017"])
print(Sales.loc["Madhu","2018"])
print(Sales.loc["Ankit","2017"])
print(Sales.loc["Ankit","2018"])
print(Sales.loc["Shruti","2016"])
Sales.loc["Sumeet"]=[196.2,37800,52000,78438,38852]
print(Sales)
Sales=Sales.drop(["2014"],axis=1)
print(Sales)
Sales=Sales.drop(["Kinshuk"],axis=0)
print(Sales)
Sales=Sales.rename ({'Ankit':'Vivaan','Madhu':'Shailesh'})
print(Sales)
Sales.loc["Shailesh","2018"]=10000
print(Sales)
DataFrame – Sales (contd.)
DataFrame – Sales (contd.)
DataFrame – Child
import pandas as pd
dict1={"Id":["001","002","003","004","005"],"Gender":["M","F","M","F","M"],
"Names":["Apple","Ball","Cat","Dog","Elephant"]}
Child=pd.DataFrame((dict1),index=["a","b","c","d","e"])
#print(Child)
Child["Age"]=[14,15,35,31,17]
#print(Child)
Child.loc["e"]=["006","F","Rachneet",82]
#print(Child)
Child.loc["d"]=["004","M","Dog",31]
print(Child)
print(Child.tail(4))
print(Child.head(2))
print(Child.index)
DataFrame – Members
import pandas as pd
dict1={"Name":["Mehak","Sarathi","Kamak"],
"Address":["Dwarka","Saket","PV"],
"Age":[22,35,38],
"Type":["Silver","Silver","Gold"],
"Fees":[1200,1000,1400]}
Members=pd.DataFrame((dict1),index=["M1","M2","M3"])
print(Members)
print(Members[["Name","Age"]] [Members["Type"]=="Gold"])
print(Members.loc["M2","Fees"] ,Members.loc["M3","Fees"])
Members.loc["M2","Address"]='Vasant Vihar'
print(Members)
Members["Fees"]=Members["Fees"]+100
print(Members)
DataFrame – Friends
import pandas as pd
dict1={'Name':["Alice","Charles","Alexander"],
'City':["Washington","Bangalore","Melbourne"],
"Age":[22,35,38],
'Country':["USA","Denmark","India"],
'Email_Id':["alice@gmail.com","null","abc@gmail.com"]}
Friends=pd.DataFrame(dict1,index=[1,2,3])
print(Friends)
print(Friends[["Name","Country"]])
print(Friends.loc[2,"Name"])
Friends.loc[4]=["Angel","New York",45,"Fance","angel@gmail.com"]
print(Friends)
Friends.loc[4,"Country"]="UK"
print(Friends)
Friends["Age"]=Friends["Age"]+10
print(Friends)
DataFrame – Details
Notebook
import pandas as pd
dict1 = {"Company": ["HCL", "HCL", "Asus"],
"Quantity":[32, 12, 46],
"Price":[18000, 14000, 15000]}
details = pd.DataFrame(dict1, index = ["Printer", "Scanner", "Monitor"])
#1st part
print(details["Price"]>15000)
#2nd part
print(details[["Quantity","Price"]])
#3rd part
print(details.loc["Printer":"Scanner"])
#4th part
df1 = details.drop("Printer", axis = 0)
print(details)
#5th part
details = details.drop("Company", axis = 1)
print(details)
To read a csv file
import pandas as pd
Details=pd.read_csv("C:/Users/jasmi/Desktop/PriceDetails.csv")
Table=pd.DataFrame(Details)
print(Table)
To convert DataFrame to csv
import pandas as pd
info={"Name":["Jasmine","Rachneet","Madhav","Satvik","Hridyanshu"],
"Age":[16,17,17,18,17],
"Class":["12-D","12-D","12-A","12-C","12-A"]}
Details=pd.DataFrame(info)
Details.to_csv(path_or_buf="C:/Users/jasmi/Desktop/Friends.csv")
import pandas as pd
import matplotlib.pyplot as plt
Friends=pd.read_csv("C:/Users\SRLAB\Desktop\Preboard_Jasmine.csv")
x=Friends["NAME"]
y=Friends["AGE"]
plt.bar(x,y,color="purple")
plt.xlabel("Name")
plt.ylabel("Age")
plt.title("Graph showing Name and Age of 3 Friends")
plt.show()
Histogram
2. Display all the details from the above table in ascending order of Area_Covered
6. Display the RTno and Area Covered for the routes where number of students is more than 100
Table - Flight
Input Values in Flight
Queries in Flight
1. Display details of all flights starting from Delhi
2. Display details of all flights that have more than 4 number of flights operating
2. Write SQL statements to, display names of salespersons who have the word “Kumar” anywhere
in the name
5. Write SQL statements to, display names of salespersons where the name starts with “R”
6. Write SQL statements to display all different areas from the table
Table - Furniture
2. To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/2002
from the FURNITURE table in descending order of ITEMNAME.
Numeric Functions
1. Power Function
3. Mod Function
String Functions
1. Uppercase Function 4. Substring Function
2. Lowercase Function
3. Length Function
String Functions (contd.)
5. Left Function 8. Ltrim Function
4. Monthname Function
Table - Product
Create the above table with appropriate data types and constraints.
Queries in Product
1. Delete the row with product name as shampoo
2. List the Product Code, Product name and price in descending order of their product name. If
PName is the same then display the data in ascending order of price.
2. Display the names of students whose names end with the character ‘a’. Also, arrange the
students in alphabetical order.
3. Display the names of students enrolled in Science and Humanities stream, ordered by student
name in alphabetical order, then by admission number in ascending order (for duplicating names).
Queries in Streams (contd.)
4. List the number of students in each stream having more than 1 student.
5. Display the names of students enrolled in different streams, where students are arranged in
descending order of admission number.