Ip Final Practical File
Ip Final Practical File
1
INTRODUCTION
2
ACKNOWLEDGEMENT
I would like to thank my teacher Mr. Deepak
Sir
for giving me the opportunity to do this
practical file. This also helped me I doing
a lot of research and increased my
knowledge in difficult topics.
3
INDEX
PYTHONPROGRAMS
S r .No Questions Tr. Sign.
1. Createaseriesofthesenumbers:33,55,65,29,19,23.
2. Createaseriesof10numbersstartingwith41andwiththe increment
of 3.
3. Createaseriesof10numbersusingndarray.
4.
Createaseriesandprintthetop3andbottom3elementsusing the
head and tail functions.
5. Writecodetoshowalattributesofseries.UseseriesinQ1.
6. UseSeriescreatedinQ2adfindoutputoffollowing commands:-
s[::2],s[1:3]&s[[1,3,4]].
7
Writecodetochangevalue29and23fromseries Q1.
14.
Create histogram to show sales of one month data.
15. Create c s v file from data frame players .Make sure null values are
4
Handled properly.
16. Create c s v file in excel .Open c s v in data frame. Make use of n rows
command.
MYSQLPROGRAMS
1. Create database DATA
Create the following table product
Table :Products
P code P name Qty Price Company
P1001 I pad 15000 Apple
P1002 LEDTV 85000 Sony
P1003 DSLR 25000 Philips
CAMERA
P1004 I Phone 95000 Apple
P1005 LEDTV 45000 MI
P1006 Bluetooth 20000 Ahuja
Speaker
9.
Show product name and qty joined with space under heading “Product and Qty”.
10. Displayfirst2andlast2lettersfromPname.
11. Write queries using e mp l table:
Show total employees working in each department.
Show avg salary of each job
Show min salary of each department where minimum employees are>3.
12. Write queries using empl and dept table:
Show employees names and location of job.
Show avg salary of employees working in sales department.
Show e name ,salary ,d name ,and location and all
13. employees. Display current date and time.
14. Display day of week, day of year and day name for current date.
15.
Write query to drop the table product.
5
PYTHONPROGRASM
1) Createaseriesofthesenumbers:33,55,65,29,19,23.
CODE:-
import pandas as pd
s1=pd.Series([33,55,65,29,19,23])
print(s1)
OUTPUT:-
2) Createaseriesof10numbersstartingwith41andwiththeincrementof3.
CODE:-
Import pandas aspd
s n = 41
I m=3
a= []
For Iin range(10):
a. append(sn)
sn = sn+im
m=pd.Series(a)
print(m)
OUTPUT:-
6
3) Createaseriesof10numbersusing ndarray.
CODE:-
Import pandas aspd
import numpy as np
s=pd. Series( np. Arrange (1,11))
print(s)
OUTPUT:-
4) Createaseriesandprintthetop3andbottom3elementsusingthehead and
tail functions.
CODE:-
Import pandas as pd
s=[10,20,30,40,50,60,70,80,90,100]
s1 = pd. Series(s)
print(s1.head(3))
print(s1.tail(3))
OUTPUT:-
7
5) WriteCODEtoshowallattributesofseries.UseseriescreatedinQ1.
CODE:-
import pandas as pd
S5=pd.Series([33,55,65,29,19,23])
print(S5[:])
OUTPUT:-
CODE:-
print(m[::2])
print(m[1:3])
print(m[[1,3,4]])
OUTPUT:-
8
7)
WriteCODEtochangevalue29and23fromseriesofQ1.
CODE:-
import pandas as pd
s1=pd.Series([33,55,65,29,19,23])
s1[3]=30
s1[5]=28
print(s1)
OUTPUT:-
9
9) Create a data frame countries using a dictionary which stored 5
country name, capital sand populations of the country. Index will
be years.
CODE:-
Import pandas as pd
countries=
pd.DataFrame(({
'Country':['USA','Canada','UK','Germany','France'],
'Capital': ['Washington D.C.', 'Ottawa', 'London', 'Berlin', 'Paris'],
'Population': [331002651,37742154, 67886011, 83783942, 65273511]
}),['2020','2021','2022','2023','2024'])
print(cou
ntries)
OUTPUT-
10) WriteprogramtoshowallattributesofdataframecreatedinQ9.
CODE:-
Import pandas as pd
import numpy as np
data={'Country':['UnitedStates','France','Brazil','Japan','Australia'],
'Capital':['Washington,D.C.','Paris','Brasília','Tokyo','Canberra'],
'Population': [1000000, 2000000, 1500000, 2500000, 1800000]}
OUTPUT-
10
11)
Create data frame players to store 10 players with their highest and lowest
score no_ of matches columns. Player names are indices of data frame.
perform following questions:-
a) Show data of any two players using loc function.
b) Show any two columns.
c) Show data of two rows and two columns using loc function.
d) Make use of rename command to change column name no_ of_ matches to
Matches_ played.
e) Drop row of last
player.
CODE:-
import pandas as pd
players=pd.Data Frame({
‘Player': ['Player1', 'Player2', 'Player3', 'Player4', 'Player5', 'Player6', 'Player7','Player8','Player9',
'Player10'],
'Highest_ Score':[98,89,95,87,99,92,96,90,88,94],
'Lowest_ Score':[45,55,50,42,48,51,46,56,49,47],
'Matches_ played':[30,35,32,33,31,29,34,30,36,37]})
players. set_ index('Player' ,in place=True)
print('a)Show data of any two players using loc function')
print(players.loc[['Player1','Player3']])
print('b)Show any two columns')
print(players[['Highest_Score',' Lowest_ Score']])
print('c) Show data of two rows and two columns using loc function')
print(players.loc[['Player2', 'Player5'], ['Highest_ Score', 'Lowest_ Score']])
print('d) Make use of rename command to change column name no_ of_ matches to
Matches_ played')
players. rename(columns={'Matches_ played': 'no_ of _matches'}, in place=True)
print('Drop the row of the last player')
players.drop('Player10', in place=True)
print('Display the updated DataFrame')
print(players)
OUTPUT:-
11
12) MakemultiplebargraphfordataframecreatedinQ.11
CODE:-
Import pandas as pd
Import matplotlib.Pyplot asplt
players=pd.DataFrame({'Playe
r': ['Player1', 'Player2',
'Player3', 'Player4', 'Player5',
'Player6', 'Player7', 'Player8',
'Player9', 'Player10'],
'Highest_ Score':[98,89,95,87,99,92,96,90,88,94],
'Lowest_ Score':[45,55,50,42,48,51,46,56,49,47],
'Matches_ played':[30,35,32,33,31,29,34,30,36,37]
})
players. set_ index('Player' ,in place=True)
players[['Highest_ Score', 'Lowest_ Score']].plot(kind='bar', fig size=(10, 6)) plt.
title('Highest and Lowest Score for Players')
plt. X label('Players') plt.Y
label('Scores') plt. X
ticks(rotation=45) plt. show()
OUTPUT:-
12
13) Create line graph for temp. of seven days of week
CODE:-
Import matplotlib.pyplot as plt
days_of_week=['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'] temperature
= [65, 68, 70, 72, 59, 57, 73]
plt. plot (days_ of_ week, temperature, marker='o', line style='-')
plt. title('Temperature for Seven Days of the Week')
plt.xlabel('Day of the Week')
plt.ylabel('Temperature(°F)')
plt.show()
OUTPUT:-
13
14) Create histogram to show sales of one month data.
CODE:-
sales_data=[110,125,125,145,135,115,110,120,135,140,130,130,140,175,135,145,125,
135,140,150,140,130,160,155,125,160,140,145]
plt.ylabel('Frequency')
plt.show()
OUTPUT:-
14
15) Create c s v file from data frame players. Make sure null values are
handled properly.
CODE:-
players=pd. DataFrame({
'Player':['Player1','Player2','Player3','Player4','Player5','Player6','Player7','Player8','Player9', 'Player10'],
'Highest_ Score':[100,150,80,None,200,90,110,130,None,170],
'Lowest_ Score':[30,40,20,50,60,35,25,None,55,70],
'Matches_ played':[50,None,60,55,40,48,None,42,47, 49]
})
players. set_ index('Player', in
place=True) players=players.
Fillna(‘N/A’) players. To _c s v
(‘players_data.csv’) OUTPUT:-
16) Create c s v file in excel. Open c s v in data frame. Make use of n rows
command.
CODE:-
import pandas as pd Df=pd. read_
c s v (‘c s v .c s v ’,n rows=5)
print(Df)
OUTPUT:-
15
MY SQL PROGRAMS
Create the following table products.
DSLR
P1003 Camera 10 25000 Philips
Bluetooth
P1006 Speaker 100 20000 Ahuja
16
1) Show table structure.
3) ShowproductsofpCODEP1001andP1005.
17
4) Show data of products starting with I .
5) Showdataofallproductswhosequantity>50andprice>30000.
7) Show product names in upper case and also length of all products
18
8) Show product name and qty joined with space under
heading “product and Qty”.
19
10) Write queries using empl table:
20
11) Write queries using empl and dept table:
21
12) Display current date and time.
13) Display day of week ,day of year and day name for current date.
22