Menu

Python Basics for Analysts

Lesson 1: Python Basics for Analysts

Why Python?

  • General-purpose: used for analysis, automation, web apps, and machine learning
  • Readable syntax: approachable for beginners
  • Huge ecosystem: libraries for almost every data task
  • Free and open-source
  • Industry demand: commonly listed in analyst and data science job descriptions

Task

Spreadsheet

Python

Quick look at 500 rowsEasy Easy
Clean 2 million rows Slow or impossiblePractical
Repeat the same cleaning monthlyManual stepsRe-run the script
Audit every stepHardCode shows every step

Variables and data types

Variables are names that hold values.

Type

Python name

Example

Typical use

Integerint12Counts
Floatfloat18450.75Money, measurements
Stringstr'South'Text, categories, IDs
BooleanboolTrue / FalseFlags
Listlist[120, 340, 560]Ordered collection, can change
Tupletuple(2026, 7)Ordered collection, can't change
Dictionarydict{'region': 'South', 'sales': 4500}Key–value pairs
NoneNoneTypeNoneMissing / no value

Choose a type that reflects how the value will be used. A postal code like '600001' is better stored as text than as a number.

Example

orders = 12
revenue = 18450.75
region = 'South'
is_returning_customer = True
average_order_value = revenue / orders
print(average_order_value) # 1537.5625
print(round(average_order_value, 2)) # 1537.56
# f-strings make readable output
print(f"AOV for {region}: ₹{average_order_value:,.2f}")

Lists and dictionaries:

monthly_sales = [12000, 15000, 13500]
print(sum(monthly_sales) / len(monthly_sales)) # average
store = {'name': 'Store A', 'city': 'Chennai', 'sales': 45000}
print(store['city']) # Chennai

How it works

  • = is the assignment operator: Python evaluates the right side, then stores it under the name on the left.
  • print() displays a value so you can inspect it.
  • type(x) tells you a variable's data type.
  • In notebooks, the last expression in a cell is displayed automatically.

Common mistakes

Mistake

Example

Fix

Case sensitivityRevenue ≠ revenueUse consistent lowercase names
Indentation errorsInconsistent spaces inside if or defUse 4 spaces consistently
Mismatched quotes'South"Use matching quotes
Mixing types'Total: ' + 100'Total: ' + str(100) or an f-string
Ignoring error messages–Read the last line of the traceback first; it names the error and line

Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details