How to create interaction matrix between users and items using pivot table

Viewed 181

My data is structured like this:

user_id, item_id

In Excel it was pretty straightforward to create pivot table that indicates if interaction occured between item and user. But I'm struggling to do this in Python. I loaded my data like this:

input_file = pd.read_csv('input_data.csv', sep=';', header=None, names=['users', 'items'])

And after that I attempted to create pivot table just like in Excel in many ways, below is one of them:

table = pd.pivot_table(input_file, columns=users, index=items)

Where users and items are ids without duplicates.

Also - is there any way of making that instead of count of interactions I could display only if interaction occured?

0 Answers
Related