Select rows where multiple column values are in multiple lists

I want to select values from a dataframe such as:

    Vendor_1   Vendor_2   Vendor_3
0   1          0          0
1   0          20         0
2   0          0          300
3   4          0          0
4   0          50         0
5   0          0          500 

The values I want to keep from Vendor_1, 2, 3 are all inside a seperate list i.e v_1, v_2, v_3. For example say say v_1 = [1], v_2 = [20], v_3 = [500], meaning I want only these rows to stay.

I’ve tried something like:

df = df[(df['Vendor_1'].isin(v_1)) & (df['Vendor_2'].isin(v_2)) & ... ]

This gives me an empty dataframe, is this problem to do with the above logic, or is it that there exist no rows with these constraints (highly unlikely in my real dataframe).

Cheers

EDIT:

Ok so I’ve realised a fundamental difference with my example and what is actually is like in my df, if there is a value for Vendor_1 then Vendor_2,3 must be 0, etc. So my logic with the isin chain doesnt make sense right, ill update the example df.

So I feel like I need to make 3 subsets and then merge them or something?

Answer

isin accepts dictionary:

d = {
    'Vendor_1':[1],
    'Vendor_2':[20],
    'Vendor_3':[500]
}

df.isin(d)

Output:

   Vendor_1  Vendor_2  Vendor_3
0      True     False     False
1     False      True     False
2     False     False     False
3     False     False     False
4     False     False     False
5     False     False      True

And then depending on your logic, you want to check for any or all:

df[df.isin(d).any(1)]

Output:

   Vendor_1  Vendor_2  Vendor_3
0         1         0         0
1         0        20         0
5         0         0       500

But if you use all in this case, for example, you require that Vendor_1=1, Vendor_2=20, and Vendor_3=500 must happen on the same rows and you would keep these rows.