0

I have the following list:

a = [1, 1193, 1219, 1210, 2115, 1198, 1197, 1196, 1136, 3793]

I also have a Dataframe with 8570 rows × 4 columns.

Now I want to have all the values of the 2nd column of the dataframe when a value of my list 'a' matches with a value of the first column of the dataframe. How can I do this in python (numpy/pandas)?

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Lnnrrt
  • 1
  • 1
    Does this answer your question? [How to determine whether a Pandas Column contains a particular value](https://stackoverflow.com/questions/21319929/how-to-determine-whether-a-pandas-column-contains-a-particular-value) – Alexandre Strapacao G. Vianna Oct 17 '20 at 16:57
  • For each value use de python command 'in'. Check [this question](https://stackoverflow.com/questions/21319929/how-to-determine-whether-a-pandas-column-contains-a-particular-value). – Alexandre Strapacao G. Vianna Oct 17 '20 at 17:02

1 Answers1

0

You can try np.isin:

import pandas as pd
df = pd.DataFrame(np.random.randint(1000, 2000, size=(1000,4)))
a = np.array([1, 1193, 1219, 1210, 2115, 1198, 1197, 1196, 1136, 3793])
a[np.isin(a, df.iloc[:,1])]

Output:

array([1219, 1198, 1197, 1196, 1136])
mathfux
  • 5,759
  • 1
  • 14
  • 34