Python Learning
5.84K subscribers
546 photos
2 videos
85 files
120 links
Python learning resources

Beginner to advanced Python guides, cheatsheets, books and projects.

For data science, backend and automation.
Join πŸ‘‰ https://rebrand.ly/bigdatachannels

DMCA: @disclosure_bds
Contact: @mldatascientist
Download Telegram
🐍 5 Python Mistakes Beginners Make (And Don’t Realize)

If you’re learning Python…
you’ve probably done these already πŸ‘‡

1️⃣ Using = Instead of == ❌

if x = 5:   # ❌ Error


πŸ‘‰ = is assignment
πŸ‘‰ == is comparison


2️⃣ Not Understanding Mutable Objects πŸ”—

a = [1, 2]
b = a

b.append(3)
print(a)


Output: [1, 2, 3]

πŸ‘‰ Both changed 😳
πŸ‘‰ Because they point to SAME object


3️⃣ Forgetting Indentation ⚠️

if True:
print("Hello") # ❌


πŸ‘‰ Python depends on indentation
πŸ‘‰ One mistake β†’ code breaks


4️⃣ Using is Instead of == 🀯

a = 1000
b = 1000

print(a is b)


πŸ‘‰ Might return False
πŸ‘‰ Because is checks memory, not value


5️⃣ Modifying List While Looping πŸ”₯

nums = [1, 2, 3]

for x in nums:
nums.remove(x)


πŸ‘‰ Leads to unexpected bugs
πŸ‘‰ Loop skips elements


πŸ’‘ Key Idea

Most bugs in Python
come from misunderstanding how it works internally πŸš€
❀3
β–ŽTop 5 Resources for Every Aspiring Python Developer


β–Ž1. Automate the Boring Stuff with Python

β€’ Type: Book/Online Course
β€’ Author: Al Sweigart
β€’ This resource is perfect for beginners who want to learn Python through practical projects. The book covers automation tasks like web scraping, working with spreadsheets, and more. The online course is available for free on platforms like Udemy.

β€’ Link: Automate the Boring Stuff


β–Ž2. Python for Everybody

β€’ Type: Online Course
β€’ Instructor: Dr. Charles Severance
β€’ This course is designed for beginners and covers the basics of programming using Python. It's structured to help learners understand data handling, web scraping, and database management.

β€’ Link: Python for Everybody


β–Ž3. Real Python

β€’ Type: Online Tutorials/Articles
β€’ Real Python offers a wealth of tutorials, articles, and video courses on various Python topics. It caters to all skill levels and includes practical examples and projects to reinforce learning.

β€’ Link: Real Python


β–Ž4. Python Crash Course

β€’ Type: Book
β€’ Author: Eric Matthes
β€’ This hands-on guide is ideal for beginners and intermediate learners. It covers the fundamentals of Python programming and includes projects such as building web applications and data visualizations.

β€’ Link: Python Crash Course


β–Ž5. The Hitchhiker's Guide to Python

β€’ Type: Book/Online Resource
β€’ Authors: Kenneth Reitz and Tanya Schlusser
β€’ This comprehensive guide offers best practices for writing Python code. It covers everything from installation to advanced topics, making it a valuable resource for both new and experienced developers.

β€’ Link: The Hitchhiker's Guide to Python
❀3
🏎 Python Performance: Vectorization vs. Loops in Pandas 🐼

In standard Python, we are taught to use for loops to process data. However, in Data Science, loops are the enemy of speed. If you use a loop to process a million rows in a Pandas DataFrame, your code will be 100x to 1000x slower than it needs to be.

πŸ‘‰ To be a pro Data Analyst, you must stop "looping" and start "vectorizing."


🐒 The Slow Way: Iterating with Loops
Python is an interpreted language, meaning every time a loop runs a calculation on a row, there is massive "overhead." The computer has to check the data type, find the memory address, and perform the math over and over again.

πŸš€ The Fast Way: Vectorization
Pandas (and NumPy) use Vectorization, which performs operations on entire arrays (columns) at once. This pushes the heavy lifting down to highly optimized C and Fortran code under the hood.


πŸ’» The "Speed Race" Code

Let's say we have 1 million rows of prices and we want to apply a 10% tax.

import pandas as pd
import numpy as np
import time

# Create a DataFrame with 1 million rows
df = pd.DataFrame({'price': np.random.randint(1, 100, size=1_000_000)})

# ❌ THE SLOW WAY: Manual Loop (Don't do this!)
start = time.time()
taxes = []
for p in df['price']:
taxes.append(p * 0.1)
df['tax_loop'] = taxes
print(f"Loop time: {time.time() - start:.4f} seconds")

# βœ… THE FAST WAY: Vectorization (The Pandas Way)
start = time.time()
df['tax_vec'] = df['price'] * 0.1
print(f"Vectorized time: {time.time() - start:.4f} seconds")


The result? The loop might take ~0.1 seconds, while the vectorized version takes ~0.001 seconds. On massive datasets, this is the difference between a task taking 10 minutes or 2 seconds.


πŸ›  When can't you vectorize?
If you have extremely complex logic (like an if/else that depends on three different external APIs), you might use .apply(). While .apply() is slightly better than a manual for loop, it is still significantly slower than true vectorization. Always try math-based column operations first.

πŸ‘‰ Write your code for the column, not for the row!
❀2