Create binary Pandas DataFrame from conversion data

Viewed 19

I currently have a dataframe with 2 columns, a visitorId and a list of all converted visited pages for each visitor (also ids).

Apart from that I also have a list of all visited pages (list of ids).

My question is how to create a binary DataFrame from this. The index would be the visitorIds and the columns would be the pageIds. The value would be 1 if the visitor converted the page and 0 otherwise.

My initial thought was just iterating over the list of all pages and create columns this way. But I was wondering if there was a neater and better way of doing this.

0 Answers
Related