2.2, 2.3 Coding Hacks
from PIL import Image, ImageFont, ImageDraw
# Allows image to be displayed in Jupyter notebook, only run in local
from IPython import display
# Open an Image from images directory
img = Image.open('images/skin1.png')
# Call draw Method to add 2D graphics in an image
draw = ImageDraw.Draw(img)
# Downloaded font, opened zip, dragged to fonts directory
myfont = ImageFont.truetype('fonts/Aloevera.ttf', 68)
# Add Text to an image, adjust coordinates/text/font/color
draw.text((120, 150), "We recommend...", font=myfont, fill=(0, 0, 0))
# Display edited image
img.show()
# Save image in images directory
img.save('images/skin2.png')
# Displays image in notebook
display.Image('images/skin2.png')
from PIL import Image
# numpy for performing batch processing and elementwise
# matrix operations efficiently
import numpy as np
# Allows image to be displayed in Jupyter notebook, only run in local
from IPython import display
display.Image("images/negatives.jpg")
from PIL import Image
# numpy for performing batch processing and elementwise
# matrix operations efficiently
import numpy as np
# Allows image to be displayed in Jupyter notebook, only run in local
from IPython import display
# Opening an image, and saving open image object
img = Image.open(r"images/negatives.jpg")
# Creating an numpy array out of the image object
img_arry = np.array(img)
# Maximum intensity value of the color mode
I_max = 255
# Subtracting 255 (max value possible in a given image
# channel) from each pixel values and storing the result
img_arry = I_max - img_arry
# Creating an image object from the resultant numpy array
inverted_img = Image.fromarray(img_arry)
# Saving the image under the name Image_negative.jpg
inverted_img.save(r"images/negatives1.jpg")
# Displays image in notebook
print("after image:")
display.Image("images/negatives1.jpg")
import pandas as pd
# reads the JSON file and converts it to a Pandas DataFrame
df = pd.read_json('files/transport.json')
print(df)
# What part of the data set needs to be cleaned?
# From PBL learning, what is a good time to clean data? Hint, remember Garbage in, Garbage out?
df2 = df["Student Age"].mean()
print("mean:", df2)
df3 = df["Student Age"].min()
print("min:", df3)
df4 = df["Student Age"].max()
print("max:", df4)
df5 = df["Student Age"].median()
print("median:", df5)
df6 = df["Student Age"].mode()
print("mode:", df6)