01_Iris

This page shows the source code for 01_Iris.py in browser-friendly HTML format. It was generated automatically from the original Python file.

Source File 01_Iris.py
Folder Chapter-5-Dataset-Advanced
# import: Imports a module or library
# as: Creates an alias for an import
import pandas as pd

# import: Imports a module or library
# as: Creates an alias for an import
import seaborn as sns

# import: Imports a module or library
# as: Creates an alias for an import
import matplotlib.pyplot as plt

# import: Imports a module or library
import os

# import: Imports a module or library
import sys

# Windows Fix

# Variable assignment
sys.stdout.reconfigure(encoding='utf-8')

# Auto-Find CSV in this folder

# Variable assignment
script_dir = os.path.dirname(os.path.abspath(__file__))

# join(): Joins strings in a list
# Documentation: https://docs.python.org/3/library/stdtypes.html#str.join
# Variable assignment
csv_file = os.path.join(script_dir, 'iris.csv')

# try: Starts a try-except block for error handling
try:

    # Variable assignment
    df = pd.read_csv(csv_file)

    # print(): Outputs text to the console
    # Documentation: https://docs.python.org/3/library/functions.html#print
    print("Data Loaded.")

# except: Catches and handles exceptions
except:

    # print(): Outputs text to the console
    # Documentation: https://docs.python.org/3/library/functions.html#print
    print("Error: CSV not found.")

# Visualize

# Variable assignment
plt.figure(figsize=(10, 6))

# Variable assignment
sns.pairplot(df, hue='species')
plt.title("Lesson: 01_Iris")
plt.show()