0 ratings0% found this document useful (0 votes) 110 views7 pagesClass 10 Ai Practical
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
ie a):
te 2}:
In (3:
‘out [3]:
In [4]:
outa):
import pandas
import pandas
‘read the csv file
pd
dfzpd.read_csv("JaipurFinalCleandata.csy-2023112771325507-001.21p")
type (df)
pandas. core. Frane.DataFrane
exploring the data
oF
ate_mean.temperatre_max.temperatre min temperature Mean dew_pt_iean_pressure maxhumily min_pumidty maxdew.plt_maxdew p12
ie
05
806
ane.
sor
ame
505
aor
ame.
tie
ze.
2010.
on
676 rows « 17 columns
I
‘to access first 5 rows of data from the Jaipur csv file
4
”
»
Py
“
e
a
Py
2
Sto access Last 5 rows of data from the Jaipur csv file
date mean temperature max tenperature in
a
ean sew pt mean pressure max husidity min huaidity
In 71
print afshead())
print af.tail())
‘Ho Find out the type of dato
of -atypes
© 2015-05-04 *
2 2016-05-06 cn
3 2016-05-07 »
5 2016-05-08 M
3 B 1000.39,
5 ® 1006.73
rin_dou pti min.deu pt.2
° 4 2
2 6 0
3 5 6
4 6 8
5 5 6
win pressure 2 rainfall
‘ 1008
date mean tenperature max tenperature min tewperature \
672 2018-03-08
ean dew pt ean pressure
on
oa
ioie.o?
toia.t6
@
2
mmox_pressure_t
Py
1009)
ro
wi
1010
1010
we
7
6
snax_pressure 2
2
1008
1008
won
1
1010
‘in_pressure_t
6
sex humidity ain punidity mas_den ptt
ss
”
3000
1003
008
1002
3002
\
100600 |
1005 05
100039
sores
101970
a
»
8
a
5
10
2
6min_dew_pt_1 min dew pt_2 max_pressure_1 max_pressure_2 \
en 3 ° 1018 1017
672 “6 3 1017 aig
673 x “6 1017 1017
674 a “5 1017 1e7
675 e a 1017 1017
win_pressure_1 min pressure 2 rainfall
on 182 1012 0.0
672 ro 1012 0.0
673 ae 1011 eo
674 11009 ao eo
675 1009 1009 e.0
out[7]: date object
mean_temperature int6@
max_fenperature Antes
‘min_temperature intea
Hean_dew pt intea
mean_pressure floatea
max humidity intea
min_hunidity intea
max_dew_pt_1 intea
min_dew_pt_1 intea
min_dew_pt_2 intea
max pressure 1 intea
max_pressure_2 intea
min_pressure_1 intea
min_pressure 2 intea
rainfall floatea
type: object
Im [6]: Ato drop 0 column
fs dfvdrop( {max dew pt.2"], axis= 1)
to sore the values in descending order of date and print the first 5 rows
Jaipur_weather= aF.sort values(by= "date", ascending- False)
print (Jatpur-weather-ead())
Fto sort the values in ascending order of mean tenperature and print the first 5 rows
jaipur westhers df. sort_values(bys “moan texperatore’, ascending True)
print Jatpur_weather-head())
date mean_tenperature max_tomperature min temperature \
7s. 2018-03-11 26 u Pn
574 2018-03-10 2% a4 9
673 2018-03-08 26 B 1
672 2018-03-08 2 2 as
67. 2018-03-07 24 3 Fr
ean_dew pt mean_pressure max humidity min_husidity maxdew pti \
os 4 1013.76 8 a 2
os a ao1e.at 2 e 5
on 2 1016.07 5s 5 a
Imin dew pt 1 min dew pt 2 max pressure 1 max pressure 2 \
os ° 4 1017 1017
era a “s 1017 1017
on 5 ea 1017 1017
on 6 3 1017 1018
om 3 ° 1018 1017
mmin_pressure_1 min_pressure 2 rainfall
675 1009 11009 0.0
674 11009 1011 0
673 1011 aon 0.0
on 1011 1012 0.0
67 1012 1011 0.0
date mean_temperature max_temperature min_temperature \
282 2017-01-11, 10 18 3
283 2017-01-12 2 19 4
258 2017-01-17 DR 20 5
285 2017-01-14 2 20 5
254 2017-01-13, 2 20 4252
253
258
255
254
252
253
258
255
24
252
253
258
255
254
rm (8)
In [10]:
Mean_dew pt mean_pressure max humidity min_humidity max dew pt_1 \
3 1017.00 34 v7 9
3 1017.54 70 B 2
3 1017.35 4 15 7
a 1017.75 70 10 1
5 1017.24 5 4 2
min_dew pt1 mindewpt_2 max_pressure 1 max pressure 2 \
*5 4 1019 1018
7 i 1020 1019
2 ° 1019 1021
“8 3 1020 1020
“3 7 1020 1020
wmin_pressure_1 min_pressure 2 rainfall
2015 1018 0.0
2015 1015 oo
2015 1015 oo
1016 1015 0.0
101s 1015 0.0
‘using matplotlib to start plotting sone graphs
Anport natplotlib.pyplot ae plt
import numpy a= np
scatter plot
Fedate
y= éf.mean_temperature
plt-scatter(x,y)
pltxticks(ap-arange(0,676,.0))
plt.xticks(rotation= 90)
add x and y labels and set a font size
plt-xlabel("Date", fontsize= 14)
plt.ylabel(*Hean temperature", fontsize= 14)
plt.title("Hean temperature at Jaipur", fontsiz
pt. show)
Mean temperature at Jaipur
Mean temperature
se 3
a
20
2016-05-04
2016-07-04
2016-09-02
2016-11-01
2016-12-31
2017-03-01
#§ 2017-04-30
2017-06-29
2017-08-28
2017-10-28
2017-12-27
2018-02-25
2In [11]: #Line plots
plt.figure(Figsize= (20,10))
x= df.date
Yt df.max temperature
yids df min temperature
y_3= df .mean_teaperature
my hy?
plt.plot(x, y_1, labels “Hox temp")
plt.plot(x, y_2, labels “Hin temp")
plt.plot(x, y3, labels “Hean temp")
plt-plot(x, 2) label= “Range")
plt.xticks(np-arange(®, 676, 60))
plt.xticks(rotation= 30)
plt.legend()
plt-shou(),
In [13]: #histogram
y= df.mean_temperature
plt.hist(y, bins= 10)
plt.xlabel('No. of days*)
plt.ylabel(“Tenperature’ )
plt.title("Probability Distribution of temperature over 2 years(2016-2018) in Jaipur’)
plt.show(),Probability Distribution of temperature over 2 years(2016-2018) in Jaipur
140
120
100
80
Temperature
60
40
20
20 25
No. of days
In [14]: import opency from matplotlib
import v2
import motplotlib
inport matplotlib.pyplot as plt
import numpy
import numpy as np
In [15]: #load the image fite into menory
ing: cv2. imread('Flower. jpg")
plt.imshow(cv2.cvtColor(img, cv2.COLOR_8GR2RGB))
plt-title(‘flower image’)
plt-axis("on")
plt.show()
print ing. shape)
flower image
1000 2000-3000
(5658, 3770, 3)In
07]
(18)
#display image as @ grayscale image
mg v2. inread(* Flower. jpg", 0) ‘the number @ opens the image as a gray:
pIt.imshow(img, cmap= “gray")
ple.title( Grayscale tage")
plt.axis("on')
plt.show()
print ing. shape)
Grayscale Image
1000 2000 +3000
(5655, 3770)
seropping im
ing= cv2.Amread( Flower jpg") ‘load the image File into menory
pl&. imshow(ev2.cvtColor(img, cv2.COLOR_8GR2RGB))
ois img{2000:3100, 14002650] fingfrange of y, range of x]
plt-imshow(ev2.evtColor(roi, ev2-COLOR_8GR2RGB))
plt.title( ‘Cropped Inage")
plt.axis(‘off")
plt.show()
Cropped ImageIn [20]: #copy ‘flower
img v2.imread(’ flower jpg)
Flower= img[2000:2100, 1400:2650)]
ing[0:1100, 0:1250]= ing[0:1100, 2500:3750]= img[4555:5800, 0:1250
plt.title( ‘copied Flowers")
plt-imshou(cv2.cvtColer(ing, cv2.COLOR_BGR2RGS))
plt.axis(’on")
plt.show()
n multiple places
mg[4555:5800, 2500:3750]= flower
8, 6, RJ= ime
print("Red-",
L Located at x=500, y-500
1G) "Blue", 8)
ev2.imerite("CopiedFlowers. pe", img)
In (27): resizing images, maintaining aspect rati
ing= cv2.imread( "Flower. jee")
print (ing. shape)
resizeds cv?. resize ing, (int (ing-shape[1]/4), int(ine.shape[0]/4)))
pit. imshow(ev2.cvtcoLor(ing, cv2-COLOR_8GR2RGE))
plt.title( Resized Image’)
pltiaxis("oFF")
plt.shon()
print (resized. shape)
Copied Flowers Resized Image
1000 2000 ©3000
(1413, 942, 3)