Excel vs SQL vs Python (pandas):
1️⃣ Filtering Data
↳ Excel: =FILTER(A2:D100, B2:B100>50) (Excel 365 users)
↳ SQL: SELECT * FROM table WHERE column > 50;
↳ Python: df_filtered = df[df['column'] > 50]
2️⃣ Sorting Data
↳ Excel: Data → Sort (or =SORT(A2:A100, 1, TRUE))
↳ SQL: SELECT * FROM table ORDER BY column ASC;
↳ Python: df_sorted = df.sort_values(by="column")
3️⃣ Counting Rows
↳ Excel: =COUNTA(A:A)
↳ SQL: SELECT COUNT(*) FROM table;
↳ Python: row_count = len(df)
4️⃣ Removing Duplicates
↳ Excel: Data → Remove Duplicates
↳ SQL: SELECT DISTINCT * FROM table;
↳ Python: df_unique = df.drop_duplicates()
5️⃣ Joining Tables
↳ Excel: Power Query → Merge Queries (or VLOOKUP/XLOOKUP)
↳ SQL: SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
↳ Python: df_merged = pd.merge(df1, df2, on="id")
6️⃣ Ranking Data
↳ Excel: =RANK.EQ(A2, $A$2:$A$100)
↳ SQL: SELECT column, RANK() OVER (ORDER BY column DESC) AS rank FROM table;
↳ Python: df["rank"] = df["column"].rank(method="min", ascending=False)
7️⃣ Moving Average Calculation
↳ Excel: =AVERAGE(B2:B4) (manually for rolling window)
↳ SQL: SELECT date, AVG(value) OVER (ORDER BY date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg FROM table;
↳ Python: df["moving_avg"] = df["value"].rolling(window=3).mean()
8️⃣ Running Total
↳ Excel: =SUM($B$2:B2) (drag down)
↳ SQL: SELECT date, SUM(value) OVER (ORDER BY date) AS running_total FROM table;
↳ Python: df["running_total"] = df["value"].cumsum()
1️⃣ Filtering Data
↳ Excel: =FILTER(A2:D100, B2:B100>50) (Excel 365 users)
↳ SQL: SELECT * FROM table WHERE column > 50;
↳ Python: df_filtered = df[df['column'] > 50]
2️⃣ Sorting Data
↳ Excel: Data → Sort (or =SORT(A2:A100, 1, TRUE))
↳ SQL: SELECT * FROM table ORDER BY column ASC;
↳ Python: df_sorted = df.sort_values(by="column")
3️⃣ Counting Rows
↳ Excel: =COUNTA(A:A)
↳ SQL: SELECT COUNT(*) FROM table;
↳ Python: row_count = len(df)
4️⃣ Removing Duplicates
↳ Excel: Data → Remove Duplicates
↳ SQL: SELECT DISTINCT * FROM table;
↳ Python: df_unique = df.drop_duplicates()
5️⃣ Joining Tables
↳ Excel: Power Query → Merge Queries (or VLOOKUP/XLOOKUP)
↳ SQL: SELECT * FROM table1 JOIN table2 ON table1.id = table2.id;
↳ Python: df_merged = pd.merge(df1, df2, on="id")
6️⃣ Ranking Data
↳ Excel: =RANK.EQ(A2, $A$2:$A$100)
↳ SQL: SELECT column, RANK() OVER (ORDER BY column DESC) AS rank FROM table;
↳ Python: df["rank"] = df["column"].rank(method="min", ascending=False)
7️⃣ Moving Average Calculation
↳ Excel: =AVERAGE(B2:B4) (manually for rolling window)
↳ SQL: SELECT date, AVG(value) OVER (ORDER BY date ROWS BETWEEN 2 PRECEDING AND CURRENT ROW) AS moving_avg FROM table;
↳ Python: df["moving_avg"] = df["value"].rolling(window=3).mean()
8️⃣ Running Total
↳ Excel: =SUM($B$2:B2) (drag down)
↳ SQL: SELECT date, SUM(value) OVER (ORDER BY date) AS running_total FROM table;
↳ Python: df["running_total"] = df["value"].cumsum()
❤3
Looks weird? You're not alone.
Python caches small integers between -5 and 256 for performance. So a and b point to the same object. But x and y are different objects, even though they have the same value.
This is part of Python's internal optimization. It’s not about math. it’s about memory references under the hood.
Bottom Line?
Use == when you care about value, not identity.
Because sometimes
Python caches small integers between -5 and 256 for performance. So a and b point to the same object. But x and y are different objects, even though they have the same value.
This is part of Python's internal optimization. It’s not about math. it’s about memory references under the hood.
Bottom Line?
Use == when you care about value, not identity.
print(x == y)
# True ✅Because sometimes
is
isn’t what you think it is 😉❤5
Feels off?
It's because all your objects share one variable (without you realizing it)
At first glance, it seems like every object should start fresh, right? But in this case, count is a class variable, which means it’s shared by all instances of the class.
Every time you create a new
If your goal is to give each object its own value, define it like this instead
Now, each instance has its own count, stored on the object itself . no sharing, no surprises.
It's because all your objects share one variable (without you realizing it)
At first glance, it seems like every object should start fresh, right? But in this case, count is a class variable, which means it’s shared by all instances of the class.
Every time you create a new
Counter()
, you’re actually incrementing the same shared variable not something unique to each object.If your goal is to give each object its own value, define it like this instead
class Counter:
def __init__(self):
self.count = 1
Now, each instance has its own count, stored on the object itself . no sharing, no surprises.
❤2
Wait, why did all functions return 2?
The lambdas don’t capture the value of
This is called late binding and can cause unexpected behavior when creating closures inside loops.
So as a quick tip, Bind the current value at definition time using a default argument(like shown in the second image) Then each lambda remembers its own
The lambdas don’t capture the value of
i
at each loop iteration, they capture the variable itself. By the time you call the functions, the loop has finished, and i
is left at its final value, 2.This is called late binding and can cause unexpected behavior when creating closures inside loops.
So as a quick tip, Bind the current value at definition time using a default argument(like shown in the second image) Then each lambda remembers its own
i
value independently.❤2