Lecture Slide 2
Lecture Slide 2
os.makedirs(path) Creates a new directory with the name path and any necessary parent directories
os.removedirs(path) Deletes the directory at path and any empty parent directories
Joins the given paths together using the appropriate separator for the current operating
os.path.join(path1, path2, ...)
system
OS library Examples
Recursive Function
• A function that call itself.
• Useful for solving problems that can be broken down into smaller, similar problems.
• To write a recursive function in Python, you use the same basic syntax as other functions, but with a base case that
ends the recursion.
• Recursive functions can be used to solve a wide range of problems, from calculating factorials and Fibonacci
numbers.
• Recursive functions can sometimes be slower and use more memory than iterative (non-recursive) solutions,
especially for large inputs.
Recursive Function (Example)
Matplotlib
• Introduced by John Hunter in 2002
• Amazing library for visualization of 2D plots in python
• Allows visual access for huge amounts of data in digestible manner.
• Consists of several plots like line, bar, scatter, histogram etc.
Importing Matplotlib
from matplotlib import pyplot as plt or
import matplotlib.pyplot as plt
Basic Plots
• Comes with wide variety plots
• Helps to understand trend, patterns and to make correlations
• Provide information for understanding quantitative information
Line plot
Box Plot
• Shows the five number summary of a set of a data
(minimum score, first quartile, median, third quartile
and maximum score)
• Useful as they show the average score of dataset.
• Useful as they also show the skewness ,
dispersion, outliers of dataset.
Boxplot Example.
Bar Plot
• Also called bar chart
• Represents the category of data with rectangular bars with lengths and heights.
• Allows to compare different sets of data among different groups easily.
• Shows the relationship among two axes
Bar Plot Example
Histogram
• Popular graphing tool.
• Shows the frequency of numerical data using rectangles.
• Height represents frequency of numerical data.
• Used to summarize discrete or continuous data measured on interval scale.
Histogram Example.
Scatter Plots
• Determine whether or not two variables have relationship or correlation.
Scatter Plots Example
Plotting (Y=mx+c)
Plotting (Y=mx+c) where m=2 and c=2
Plotting (Y=mx+c) where m=2 and c=2
Key things to remember
• xlim – set upper and lower limits of x-axis
• ylim – set upper and lower limit of y-axis.
• xlabel – set label for x-axis
• ylabel – set label for y-axis
• legend – add legend to the plot
• title – add title to the plot
• xticks – set custom marker for the x-axis
• yticks – set custom marker for the y-axis
Example
Pie Chart
Any Questions ?