Pages

ALL PAGES

Pages

Sunday, 27 July 2025

 bhai kya kar raha hai tu faltu ki cheeze hai usme dhyan lagta hai subh ka time waste ho raha hai kuch kar le firse tu usshi fase m average jee adv tu manta hai khud ko google level pe sach batyiyo please kar le 

gate mat chod if ek saal dhag se kare toh kyon ni hoga ek reason de mujhe 

Saturday, 12 July 2025

13 july 2025

Subh

Discrete maths 

2 leetcode 

Machine learning andrew 





Shaam ko 

Computer vision more then 2 hour lecture ye more bhi 
 
1 leetcode 






Raat ko 

1. DSA ka lecture do 

2. Discrete maths 

3. Leetcode 


Friday, 4 July 2025

How to use apply

 kaise use karna Bhai .apply() Pandas ka most used aur most powerful function hai — ye tab use hota hai jab:

Tum har row ya har column pe koi custom operation lagana chahte ho — especially jab woh operation ek simple loop se slow ho jata.

Ab main tujhe .apply() ka use learnable format mein sikhata hoon — taaki logic bhi samjhe, aur yaad bhi rahe.


🧠 Step-by-Step Learnable Format:


✅ 1. .apply() on a column (Series pe)

📌 Use case: Ek column ke sabhi values ka square nikalna

import pandas as pd

df = pd.DataFrame({
    'number': [1, 2, 3, 4, 5]
})

df['square'] = df['number'].apply(lambda x: x**2)

print(df)

📤 Output:

   number  square
0       1       1
1       2       4
2       3       9
3       4      16
4       5      25

🧠 Learn this logic:

df['col'].apply(function) = apply this function to each value of the column


✅ 2. .apply() with a custom function

def label_even_odd(x):
    return "even" if x % 2 == 0 else "odd"

df['type'] = df['number'].apply(label_even_odd)

📤 Output:

   number  type
0       1   odd
1       2  even
...

🧠 Learn this logic:

Define function → Apply on column → Return new values


✅ 3. .apply() on multiple columns (axis=1)

📌 Use case: Combine first & last name

df = pd.DataFrame({
    'first': ['Rahul', 'Priya'],
    'last': ['Sharma', 'Verma']
})

df['full_name'] = df.apply(lambda row: row['first'] + ' ' + row['last'], axis=1)

📤 Output:

   first   last   full_name
0  Rahul  Sharma  Rahul Sharma
1  Priya   Verma  Priya Verma

🧠 Logic:

df.apply(lambda row: ..., axis=1) = Apply function on each row


✅ 4. .apply() + if conditions

📌 Use case: Category tagging

df = pd.DataFrame({'marks': [90, 60, 40, 30]})

df['grade'] = df['marks'].apply(lambda x: 'A' if x >= 75 else ('B' if x >= 50 else 'C'))

📤 Output:

   marks  grade
0     90      A
1     60      B
2     40      C
...

🧠 Logic:

Use nested if-else inside lambda to apply conditions


✅ 5. .apply() on list column

📌 Use case: Length of strings in list

df = pd.DataFrame({'words': ['hello', 'world', 'pandas', 'rocks']})

df['length'] = df['words'].apply(len)

📤 Output:

   words   length
0  hello        5
1  world        5
...

🧠 Logic:

.apply(len) → len is a function → used on each cell


🧠 Summary Cheat Sheet:

Use CaseCode Example
Column pe functiondf['col'].apply(lambda x: x*2)
Custom funcdf['col'].apply(my_func)
Multiple columnsdf.apply(lambda row: ..., axis=1)
Conditionapply(lambda x: 'yes' if x > 50 else 'no')
List pe applydf['list_col'].apply(len)

🔥 Practice Task for You:

Try writing this:

👉 Maan lo ek DataFrame hai:

df = pd.DataFrame({'temperature': [30, 40, 50]})

Tumhe ek naya column banana hai:

'status' = 'hot' if temp >= 40 else 'normal'

Try this using .apply() and lambda. Agar chaahe toh bhej, main verify kar dunga.


Aur bhai agar tu .applymap() or .map() ka confusion chahta clear karna, toh woh bhi kara deta hoon side-by-side comparison se.