Beginner

Python Data Essentials: Python Introduction

Get started with Python for data science — the basics, packages and core data structures.

Table of Contents


Module 1 — Course Overview

This course introduces the fundamentals of Python applied to data science. It targets beginners who want to understand the key concepts needed to start working with data in Python.

Topics covered:

  • Data structures (lists, tuples, sets)
  • Operators (arithmetic, comparison, logical)
  • Packages and managing them with pip
  • Identifiers and literals

Prerequisites: Basic understanding of what programming is.


Module 2 — Python and Data Science

What Is Python?

Python is one of the most powerful and versatile programming languages available today. Key characteristics:

  • Open source — freely usable, even for commercial purposes
  • Interpreted — executed line by line, not compiled as a block
  • Portable — same code works on Windows, macOS and Linux
  • Object-oriented — everything in Python is an object

Use cases:

  • Web and desktop applications
  • Automation of repetitive tasks
  • Data science and machine learning
  • Scripting and system administration

Python Features

FeatureDescription
Object-orientedEverything is an object; full OOP principles support
InterpretedLine-by-line execution by the Python interpreter
PortableIdentical code on Windows, macOS, Linux
Rich in librariesGlobal community, thousands of packages available
ReadableClear syntax close to natural language

Python Packages for Data Science

# The major Data Science packages
import numpy      # NumPy       — multidimensional arrays, numerical computing
import pandas     # Pandas      — tabular data manipulation (DataFrames)
import matplotlib # Matplotlib  — visualization and charts
import sklearn    # Scikit-learn — machine learning
PackageMain Purpose
NumPyN-dimensional arrays, vectorized mathematical operations
PandasDataFrames, data cleaning, transformation and analysis
MatplotlibCharts and visualizations (line charts, histograms, scatter plots)
Scikit-learnSupervised and unsupervised machine learning algorithms

Why Python for Data Science?

  1. Simplicity — readable syntax, gentle learning curve
  2. Rich ecosystem — NumPy, Pandas, Matplotlib, Scikit-learn, TensorFlow…
  3. Community — millions of developers, abundant documentation
  4. Jupyter Notebook — ideal interactive environment for data exploration
  5. Integration — easily connects to databases, APIs, and cloud tools

Installing Python

On Windows via PowerShell:

# Check if Python is already installed
python3 --version

# If Python is not found, launch installation from Microsoft Store
python3
# → Automatically opens Microsoft Store with the Python app

Post-installation verification:

python3 --version
# Output: Python 3.x.x

pip --version
# pip is included with Python 3 — no separate installation needed

Tip: pip (Package Installer for Python) is automatically available with any recent Python 3 installation.

Python IDEs

An IDE (Integrated Development Environment) is a tool that enhances developer productivity through advanced features.

IDE advantages:

  • Syntax highlighting — keywords are highlighted, code is more readable
  • Autocomplete — code suggestions while typing (fewer errors, faster)
  • Integrated debugging — tools for finding and fixing errors
  • Git integration — version control directly in the IDE

Popular Python IDEs:

IDEDescription
PyCharmProfessional Python-dedicated IDE (JetBrains), very comprehensive
Visual Studio CodeLightweight and extensible editor, very popular in the community
AtomOpen source and customizable editor
Jupyter NotebookInteractive environment, ideal for data science

Installing Jupyter Notebook

Jupyter Notebook is an interactive environment that allows writing and executing Python code in cells, alongside explanatory text (Markdown). It is particularly used in data science for data exploration and visualization.

# Installation via pip
pip install jupyter

# Launch Jupyter Notebook
jupyter notebook
# → Automatically opens browser at http://localhost:8888

Basic Jupyter usage:

  • Code cell — write and execute Python
  • Markdown cell — write formatted text, titles, formulas
  • Shift + Enter — execute current cell and move to next
  • Ctrl + Enter — execute current cell without moving

Module 3 — Python Basics

Identifiers and Literals

Identifiers

An identifier is the name given to a variable, function, class, or any other Python object. Through identifiers, Python recognizes and distinguishes the different elements of a program.

Rules for identifiers:

RuleValid ExampleInvalid Example
Cannot start with a digitname11name
No special characters (except _)my_varmy-var, my@var
No Python reserved wordsmy_listlist, for, if
Case-sensitiveNamename

Python reserved keywords:

False    None     True     and      as       assert   async
await    break    class    continue def      del      elif
else     except   finally  for      from     global   if
import   in       is       lambda   nonlocal not      or
pass     raise    return   try      while    with     yield

Literals

A literal is a value directly written in the source code — a constant value.

# Numeric Literals — integers
a = 10
print(type(a))   # <class 'int'>

# Numeric Literals — floats
a = 5.2
print(type(a))   # <class 'float'>

# String Literals — double or single quotes
greeting = "Hello Python"
print(type(greeting))   # <class 'str'>

greeting = 'Hello Python'   # Identical to previous
print(type(greeting))       # <class 'str'>

# Boolean Literals
a = True
print(type(a))   # <class 'bool'>

a = False
print(type(a))   # <class 'bool'>

Python literal types:

TypeExampleClass
Integer42, -7, 0int
Float3.14, -0.5float
String"hello", 'world'str
BooleanTrue, Falsebool
NoneNoneNoneType

Expressions and Operators

An expression is a combination of operands (values) and operators that produces a computed value.

# Expression examples
6 + 6      # → 12  (operand + operand → result)
10 - 3     # → 7
5 * 4      # → 20

print(6 + 6)    # 12
print(10 - 3)   # 7
print(5 * 4)    # 20

Terminology: In 6 + 6, the two 6s are the operands and + is the operator.

Three operator categories in Python:

  1. Arithmetic Operators — mathematical operations
  2. Comparison Operators — comparisons returning a boolean
  3. Logical Operators — boolean logic

Arithmetic Operators

a = 10
b = 4

print(a + b)    # 14 — Addition
print(a - b)    # 6  — Subtraction
print(a * b)    # 40 — Multiplication
print(a / b)    # 2.5 — Division (always returns float)
print(a % b)    # 2  — Modulo (remainder of integer division)
print(a // b)   # 2  — Floor division (rounds toward -∞)
print(a ** b)   # 10000 — Exponent (10^4)

Summary table:

OperatorSymbolExample (a=10, b=4)Result
Addition+a + b14
Subtraction-a - b6
Multiplication*a * b40
Division/a / b2.5
Modulo%a % b2
Floor division//a // b2
Exponent**a ** b10000

Comparison Operators

Comparison operators compare two values and always return a boolean (True or False).

a = 10
b = 4
c = 4

print(a == b)   # False — Equal to (== not =)
print(b == c)   # True

print(b != c)   # False — Not equal to
print(a > c)    # True  — Greater than
print(b < a)    # True  — Less than
print(b <= c)   # True  — Less than or equal to
print(b >= c)   # True  — Greater than or equal to

Important: = is the assignment operator, == is the comparison operator.

Logical Operators

Logical operators work on boolean operands and are used in decision-making.

# Logical AND — true only if BOTH operands are True
print(True and False)   # False
print(True and True)    # True

# Logical OR — true if AT LEAST ONE operand is True
print(True or False)    # True
print(False or False)   # False

# Logical NOT — inverts the boolean value
print(not True)         # False
print(not False)        # True

# Using with expressions
a = 10
b = 4
c = 4

print((b >= c) and (b <= c))   # True and True  → True
print((b >= c) and (a <= c))   # True and False → False
print((b >= c) or (a <= c))    # True or False  → True

Truth table:

ABA and BA or Bnot A
TrueTrueTrueTrueFalse
TrueFalseFalseTrueFalse
FalseTrueFalseTrueTrue
FalseFalseFalseFalseTrue

Module 4 — Packages and Data Structures

Packages in Python

What Is a Module?

A module is a Python file (.py) containing variables, functions, and classes, designed to be imported and reused in other programs.

What Is a Package?

A package is a grouping of related modules sharing a common functionality. It’s the equivalent of a folder in your file system: just as you group your files by category in folders, you organize Python modules in packages.

Using a package:

import camelcase

c = camelcase.CamelCase()
s = 'how are you?'
print(c.hump(s))   # → 'How Are You?'

PyPI — Python Package Index

PyPI (pypi.org) is the official repository of all public Python packages. This is where pip searches for packages during installation.

Using pip

pip is Python’s package manager. It allows installing, updating, and uninstalling third-party packages.

# Install a package
pip install camelcase
pip install jupyter
pip install numpy pandas matplotlib

# Uninstall a package
pip uninstall camelcase

# List installed packages
pip list

# View package details
pip show numpy

# Install a specific version
pip install numpy==1.24.0

# Update a package
pip install --upgrade numpy

# Save dependencies to a file
pip freeze > requirements.txt

# Install dependencies from a file
pip install -r requirements.txt

Importing a package in code:

# Full import
import numpy

# Import with alias (recommended convention)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

# Selective import (import only what's needed)
from datetime import datetime
from os import path

Data Structures — Overview

A data structure is a way of organizing and storing data efficiently for easier processing.

Python provides three main built-in data structures:

Data StructureSymbolsOrderedMutableDuplicates
List[ ]YesYes (mutable)Yes
Tuple( )YesNo (immutable)Yes
Set{ }NoNo*No

* A set cannot be modified by indexing, but you can add/remove elements with add() and remove().

Lists

A list is an ordered and mutable collection that can contain elements of different types.

Creating Lists

# String list
my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]
print(my_list)          # ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']
print(type(my_list))    # <class 'list'>

# Number list
numbers_list = [1, 2, 3, 4, 5]

# Mixed-type list
mixed_list = [1, 'alice', 2.5]

# Nested list
nested_list = [1, 'alice', 2.5, ['a', 'b', 'c']]

# Empty list
empty_list = []
print(type(empty_list))   # <class 'list'>

Accessing Elements (Indexing)

my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]

# Positive indexing (starts at 0)
print(my_list[0])   # Alice
print(my_list[1])   # Bob

# Negative indexing (from the end)
print(my_list[-1])  # Eve
print(my_list[-5])  # Alice  (equivalent to index 0)

# Access element in nested list
nested = [1, 'alice', 2.5, ['a', 'b', 'c']]
print(nested[3][1])  # b

Modifying a List

my_list = ["Alice", "Bob", "Charlie", "Dave", "Eve"]

# Modify an existing element
my_list[0] = "Alexandra"
print(my_list)   # ['Alexandra', 'Bob', 'Charlie', 'Dave', 'Eve']

# Add an element at the end
my_list.append("Frank")
print(my_list)   # ['Alexandra', 'Bob', 'Charlie', 'Dave', 'Eve', 'Frank']

List Characteristics

# 1. MUTABLE
my_list[0] = "Alexandra"   # ✓ Works

# 2. ORDERED — element order is preserved

# 3. ALLOWS DUPLICATES
dup_list = ["Alice", "Bob", "Bob", "Charlie"]
print(dup_list)   # ["Alice", "Bob", "Bob", "Charlie"] — Bob appears twice

Tuples

A tuple is an ordered and immutable (unmodifiable after creation) collection. Use a tuple when you want to protect data from accidental modification.

Creating Tuples

# String tuple (round parentheses)
my_tuple = ('apple', 'banana', 'cherry')
print(my_tuple)         # ('apple', 'banana', 'cherry')
print(type(my_tuple))   # <class 'tuple'>

# Single-element tuple — the trailing comma is mandatory!
single = ('apple')      # NOT a tuple — it's a str
print(type(single))     # <class 'str'>

single = ('apple',)     # Single-element tuple
print(type(single))     # <class 'tuple'>

# Mixed-type tuple
mixed_tuple = ('apple', 'banana', 'cherry', 10, 11.5)

# Empty tuple
empty_tuple = ()
print(type(empty_tuple))   # <class 'tuple'>

Accessing Elements

my_tuple = ('apple', 'banana', 'cherry')

print(my_tuple[0])   # apple
print(my_tuple[2])   # cherry

# in operator — check element presence
print('apple' in my_tuple)        # True
print('apple' not in my_tuple)    # False
print('watermelon' in my_tuple)   # False

Tuple Packing and Unpacking

# Tuple Packing — group multiple variables into a tuple
name = "Alice"
age = 25
city = "New York"
packed_tuple = name, age, city
print(packed_tuple)   # ('Alice', 25, 'New York')

# Tuple Unpacking — decompose a tuple into separate variables
person = ('Alice', 25, 'New York')
name, age, city = person
print(name)   # Alice
print(age)    # 25
print(city)   # New York

# Tuple returned by a function
def get_user_info():
    name = "John Doe"
    age = 30
    city = "Los Angeles"
    return name, age, city   # implicitly returns a tuple

name, age, city = get_user_info()
print("Name:", name)
print("Age:", age)
print("City:", city)

Tuple Characteristics

my_tuple = ('apple', 'banana', 'cherry')

# 1. IMMUTABLE
my_tuple[0] = "grape"   # ✗ TypeError: 'tuple' object does not support item assignment

# 2. ORDERED — order is preserved

# 3. ALLOWS DUPLICATES
dup_tuple = ('apple', 'banana', 'apple')   # Valid

Sets

A set is an unordered collection without duplicates. Ideal for storing unique values or performing set operations (union, intersection).

Creating Sets

# String set (curly braces)
my_set = {'alice@example.com', 'bob@example.com', 'charlie@example.com'}
print(my_set)          # Order not guaranteed
print(type(my_set))    # <class 'set'>

# Set automatically removes duplicates
dup_set = {'apple', 'banana', 'apple', 'cherry', 'banana'}
print(dup_set)         # {'apple', 'banana', 'cherry'} — no duplicates

# Empty set — IMPORTANT: {} creates a dict, not a set
empty_set = set()
print(type(empty_set))   # <class 'set'>

# Create a set from a list
from_list = set([1, 2, 2, 3, 3, 4])
print(from_list)   # {1, 2, 3, 4}

Set Operations

set_a = {1, 2, 3, 4, 5}
set_b = {3, 4, 5, 6, 7}

# Union — all elements from both sets
print(set_a | set_b)           # {1, 2, 3, 4, 5, 6, 7}
print(set_a.union(set_b))

# Intersection — elements in both sets
print(set_a & set_b)           # {3, 4, 5}
print(set_a.intersection(set_b))

# Difference — elements in A but not in B
print(set_a - set_b)           # {1, 2}
print(set_a.difference(set_b))

# Check membership
print(3 in set_a)              # True
print(6 in set_a)              # False

# Add/remove elements
set_a.add(6)
set_a.remove(1)   # Raises KeyError if not found
set_a.discard(99) # No error if not found

Reference Diagrams

Python Data Types

graph TD
    PY[Python Data Types] --> NUM[Numeric]
    PY --> SEQ[Sequence]
    PY --> SET_T[Set]
    PY --> MAP[Mapping]
    PY --> BOOL[Boolean]
    PY --> NONE[None]

    NUM --> INT[int]
    NUM --> FLOAT[float]
    NUM --> COMPLEX[complex]

    SEQ --> STR[str]
    SEQ --> LIST[list]
    SEQ --> TUPLE[tuple]

    SET_T --> SET_V[set]
    SET_T --> FROZENSET[frozenset]

    MAP --> DICT[dict]

    style INT fill:#4CAF50,color:#fff
    style FLOAT fill:#4CAF50,color:#fff
    style STR fill:#2196F3,color:#fff
    style LIST fill:#FF9800,color:#fff
    style TUPLE fill:#9C27B0,color:#fff
    style SET_V fill:#F44336,color:#fff
    style DICT fill:#00BCD4,color:#fff

Virtual Environment and pip

flowchart LR
    PyPI[(PyPI\npypi.org\nPackage Registry)] -->|pip install| LocalEnv[Local Environment\n.venv/]
    LocalEnv --> Script[Python Script\napp.py]
    Script -->|import| Pkg[Installed\nPackages]

    style PyPI fill:#306998,color:#fff
    style LocalEnv fill:#FFD43B,color:#000

Reference Tables

Base Types (built-in types)

Python TypeKeywordExampleDescription
Integerint42, -7Whole number
Floatfloat3.14, -0.5Decimal number
Complexcomplex2+3jComplex number
Stringstr"hello", 'world'Character string
BooleanboolTrue, FalseTrue or false value
NoneTypeNoneNoneAbsence of value
Listlist[1, 2, 3]Ordered mutable collection
Tupletuple(1, 2, 3)Ordered immutable collection
Setset{1, 2, 3}Unordered collection without duplicates
Dictionarydict{'a': 1}Key-value pairs

Python Operators

Arithmetic Operators

OperatorSymbolExampleResult
Addition+10 + 414
Subtraction-10 - 46
Multiplication*10 * 440
Division/10 / 42.5
Floor Division//10 // 42
Modulo%10 % 42
Exponent**10 ** 410000

Comparison Operators

OperatorSymbolDescription
Equal to==Equality
Not equal to!=Inequality
Greater than>Strictly greater
Less than<Strictly less
Greater or equal>=Greater than or equal
Less or equal<=Less than or equal

Logical Operators

OperatorDescriptionExample
andTrue if both operands are TrueTrue and FalseFalse
orTrue if at least one operand is TrueTrue or FalseTrue
notInverts the boolean valuenot TrueFalse

Essential Built-in Functions

FunctionDescriptionExample
print()Display a value in the consoleprint("Hello")
type()Return the type of an objecttype(42)<class 'int'>
len()Return the length of a sequencelen([1,2,3])3
input()Read user inputname = input("Name: ")
int()Convert to integerint("42")42
float()Convert to floatfloat("3.14")3.14
str()Convert to stringstr(42)"42"
bool()Convert to booleanbool(0)False
list()Create or convert to listlist((1,2,3))[1,2,3]
tuple()Create or convert to tupletuple([1,2,3])(1,2,3)
set()Create or convert to setset([1,1,2]){1,2}
range()Generate a number sequencerange(5)0,1,2,3,4

Data Structures Comparison

CriterionList []Tuple ()Set {}
Creation[1, 2, 3](1, 2, 3){1, 2, 3}
OrderedYesYesNo
MutableYesNoPartially
DuplicatesYesYesNo
Index accessYesYesNo
Use casesDynamic collectionsFixed data, function returnsUnique values, set operations
PerformanceO(n) searchO(n) searchO(1) search

Search Terms

python · data · essentials · foundations · analysis · engineering · analytics · operators · comparison · packages · science · structures · accessing · arithmetic · built-in · characteristics · elements · identifiers · installing · list · lists · literals · logical · package

Interested in this course?

Contact us to book it or get a custom training plan for your team.