The only issue is your array slicing
df = pd.DataFrame({"col2":np.random.randint(1,50,100)})
df[df["col2"].isin(df['col2'].unique()[:5])]
output
|
col2 |
0 |
3 |
1 |
13 |
2 |
1 |
3 |
27 |
4 |
4 |
9 |
1 |
20 |
13 |
27 |
1 |
31 |
4 |
35 |
4 |
42 |
13 |
43 |
27 |
48 |
3 |
59 |
4 |
60 |
4 |
67 |
4 |
90 |
3 |
95 |
4 |
96 |
4 |
98 |
13 |
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…