This page shows the source code for 05_Penguins.py in browser-friendly HTML format. It was generated automatically from the original Python file.
# 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, 'penguins.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.violinplot(data=df, x='species', y='flipper_length_mm')
plt.title("Lesson: 05_Penguins")
plt.show()