Practical-Data Science: Delhi Public School Bangalore - East Artificial Intelligence Advance Python
Practical-Data Science: Delhi Public School Bangalore - East Artificial Intelligence Advance Python
Practical-Data Science: Delhi Public School Bangalore - East Artificial Intelligence Advance Python
ARTIFICIAL INTELLIGENCE
ADVANCE PYTHON
#To access first 5 rows of data from the Jaipur csv file
print(df.head())
#To access last 5 rows of data from the Jaipur csv file
df.tail()
# To Drop a column
df = df.drop(["max_dew_pt_2"], axis=1)
# To Sort the values in descending order of date and print the first 5 rows
jaipur_weather = df.sort_values(by='date',ascending = False)
print(jaipur_weather.head())
# To Sort the values in ascending order of mean temperature and print the first 5 rows
jaipur_weather = df.sort_values(by='mean_temperature',ascending = True)
print(jaipur_weather.head())
# Using matplotlib to start plotting some graphs
import matplotlib.pyplot as plt
import numpy as np
# Scatter Plot
x = df.date
y = df.mean_temperature
plt.scatter(x,y)
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=90)
# Add x and y labels and set a font size
plt.xlabel ("Date", fontsize = 14)
plt.ylabel ("Mean Temperature", fontsize = 14)
plt.title('Mean Temperature at Jaipur', fontsize = 20)
plt.show()
# Line Plots
plt.figure(figsize=(20,10))
x = df.date
y_1 = df.max_temperature
y_2 = df.min_temperature
y_3 = df.mean_temperature
z = y_1-y_2
plt.plot(x,y_1, label = "Max temp")
plt.plot(x,y_2, label = "Min temp")
plt.plot(x,y_3, label = "Mean temp")
plt.plot(x,z, label = "range")
plt.xticks(np.arange(0, 676, 60))
plt.xticks (rotation=30)
plt.legend()
plt.show()
**************
Practical- Computer Vision
Type the below codes in Jupyter Notebook and Execute/Run them for the output. Take the printout of
the codes along with their outputs and stick them on plain side(left) of the Journal. Also write the codes
(without the output) on the ruled side.
Make sure Images folder (with images) is in the same folder as the Jupyter Notebook.
# Cropping images
img = cv2.imread('Images/flower.jpg') #Load the image file into memory
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
roi = img[2000:3100,1400:2650] #img[range of y, range of x]
plt.imshow(cv2.cvtColor(roi, cv2.COLOR_BGR2RGB))
plt.title('flower')
plt.axis('off')
plt.show()
# Copy 'flower' in multiple places
img = cv2.imread('Images/flower.jpg')
flower = img[2000:3100,1400:2650]
img[0:1100,0:1250]=img[0:1100,2500:3750]=img[4555:5800,0:1250]=img[4555:5800,2500:3750]=flower
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('more flowers')
plt.axis('on')
plt.show()
# access the RGB pixel located at x=500, y=500
[B,G,R] = img[500, 500] #img[y,x]
print('Red=', R, 'Green=', G, 'Blue=',B)
*************