I am using pandas library to read data from a .json file. I have the following example dataset:
import pandas as pd
df = pd.DataFrame([['1', 'book1'],
['1', 'book2'],
['1', 'book6'],
['2', 'book1'],
['2', 'book6'],
['2', 'book3'],
['3', 'book4'],
['3', 'book2'],
['4', 'book3'],
],
columns=['visitor_id', 'bookid'])
This dataset shows the user_id and which book this user has read. My question is, is it possible to filter out the list of books other users have read based on a given book value? For example, which other books other users have read which also read book 1. So the result should have 'book6', 'book3' and 'book2' if I were to search for 'book1'.
Is it possible to do it directly using any pandas function? The closest I could find in the documentation was groupby() function but I could not get it to work. I want to avoid going through each value using a loop as my dataset is quite big.