Wednesday, 17 September 2025

df.corr().stack() or unstack()

 


2nd way 

import pandas as pd


# Example DataFrame

data = {

    "A": [1, 2, 3, 4, 5],

    "B": [2, 4, 6, 8, 10],

    "C": [5, 4, 3, 2, 1],

    "D": [10, 20, 30, 40, 50]

}

df = pd.DataFrame(data)


# Correlation matrix

corr = df.corr()


# Filter correlations > 0.5 (excluding self-correlation = 1.0)

filtered = corr[(corr > 0.5) & (corr < 1.0)]


print("Correlation > 0.5:")

print(filtered)

🟢 Output Example

Correlation > 0.5:

     A    B    C    D

A  NaN  1.0  NaN  1.0

B  1.0  NaN  NaN  1.0

C  NaN  NaN  NaN  NaN

D  1.0  1.0  NaN  NaN

Wednesday, 27 August 2025

code for interface

 import java.util.*;


// Given Interface (Leetcode style)

interface NestedInteger {

    boolean isInteger();

    Integer getInteger();

    List<NestedInteger> getList();

}


// Implementation for testing

class NI implements NestedInteger {

    private Integer value;

    private List<NestedInteger> list;


    public NI(Integer val) { 

        this.value = val; 

        this.list = null;

    }


    public NI(List<NestedInteger> list) { 

        this.list = list; 

        this.value = null;

    }


    @Override

    public boolean isInteger() {

        return value != null;

    }


    @Override

    public Integer getInteger() {

        return value;

    }


    @Override

    public List<NestedInteger> getList() {

        return list;

    }

}


// Iterator class

class NestedIterator implements Iterator<Integer> {

    private Queue<Integer> q = new LinkedList<>();


    public NestedIterator(List<NestedInteger> nestedList) {

        flatten(nestedList);

    }


    private void flatten(List<NestedInteger> nestedList) {

        for (NestedInteger ni : nestedList) {

            if (ni.isInteger()) {

                q.add(ni.getInteger());

            } else {

                flatten(ni.getList());

            }

        }

    }


    @Override

    public Integer next() {

        return q.poll();

    }


    @Override

    public boolean hasNext() {

        return !q.isEmpty();

    }

}


public class Main {

    public static void main(String[] args) {

        // Input: [[1,1], 2, [1,1]]

        List<NestedInteger> input = new ArrayList<>();


        input.add(new NI(Arrays.asList(new NI(1), new NI(1))));

        input.add(new NI(2));

        input.add(new NI(Arrays.asList(new NI(1), new NI(1))));


        NestedIterator i = new NestedIterator(input);

        while (i.hasNext()) {

            System.out.print(i.next() + " ");

        }

    }

}


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.

Wednesday, 25 June 2025

25 june 2025

 1. subh leetcode

2. and deep learning ka resnet and all

1 baje so gaya main 

3. 5 baje se dsa ka ek vidoe dekha 6 baje tak 

wasted 2 hour bich mein

4. 8 baje maine start kiya deep learning coursera ka 

ye kiya badiya

leetcode ka ek question 


5 .raat ko leetcode ke question mein time lag agay 

6. discrte maths


24 june 2025

 1. Subh ka time do video discrete  

2. backprop ka ek video 

then waste hi hu 


3. shaam ko 5 bje se 

1. deep learing campsx wale ka 3 video dekhe 

2. leetcode 1 question

3. Data structure and algo -: atelast 1 video 


Hello

df.corr().stack() or unstack()

  2nd way  import pandas as pd # Example DataFrame data = {     "A": [1, 2, 3, 4, 5],     "B": [2, 4, 6, 8, 10],     ...