I have an carid and I would like to see all buyers who had something to do with this carid. So I would like to have all buyers who have bought carid 3.
How do I do that?
import pandas as pd
d = {'Buyerid': [1,1,2,2,3,3,3,4,5,5,5],
     'Carid': [1,2,3,4,4,1,2,4,1,3,5]}
df = pd.DataFrame(data=d)
print(df)
    Buyerid  Carid
0         1      1
1         1      2
2         2      3
3         2      4
4         3      4
5         3      1
6         3      2
7         4      4
8         5      1
9         5      3
10        5      5
# What I want
    Buyerid  Carid
2         2      3
3         2      4
8         5      1
9         5      3
10        5      5
I have already tested this df = df.loc[df['Carid']==3,'Buyerid'], but this only gives me the line with CardID 3 but not the complete buyer.
How to select rows from a DataFrame based on column values
I looked at that, but I only get this here
   Buyerid  Carid
2         2      3
9         5      3
 
     
    