I don't know how i pivot table in picture one to square matrix in table 2.
Value is distinct count anonymous_id
Want to know how many users join in event voucher denied
and item_checkout_started
, etc. ?
Thanks!
CodePudding user response:
pivot require 3 argumnts:
- index (anonymous_id) - in this case
- column - Column to use to make new frame’s columns.
- values - Column(s) to use for populating new frame’s values.
df.pivot(index=["anonymous_id"], columns=["list_event_n"],values="at")
CodePudding user response:
Use pd.crosstab
, as follows:
pd.crosstab(df['anonymous_id'], df['list_event_n'])
Result:
list_event_n item_checkout_started item_viewed outlet_list_viewed outlet_product_clicked outlet_promo_clicked popup_registered popup_viewed product_clicked product_list_viewed product_searched product_viewed promotion_viewed
anonymous_id
1smryT8ImQLcG2DujbmnSzZPzdv 0 0 0 0 1 0 0 0 0 0 0 0
1sn2WS2DIi6DzM0LEdhKiCjnKkp 0 0 0 0 1 0 0 0 0 0 0 0
1sn6i04LsEI8Cgjzd1BdDW8n9cH 0 0 0 0 0 0 0 0 0 0 1 0
1snHTT4qu5fCsnxRIRiYUD22rH4 0 1 0 0 0 0 0 0 0 0 0 0
1sr24cc1DNqKJBTNQJpDrol4nYf 0 0 0 0 0 0 0 1 0 0 1 0
1t4tA8igP7HwSivoop65QYRAvxi 0 0 0 0 0 0 0 1 0 0 1 0
1tP1HAURwG4NLSkLgM4g4Af35Uq 0 1 0 0 0 0 0 0 0 0 0 0
1uYwjMt8a1BK8UxBSj9oNo4IPTe 0 0 0 0 0 0 0 1 0 0 1 0
1uceWfGy8FOsnX6HQe7kpjAJrZ5 0 0 0 0 1 0 0 0 0 0 0 0
1uci9RelkZpdkjFBxBw5vVXynZU 0 0 1 0 0 0 0 0 0 0 0 0
1ucpPwjhgZBYPA95xcLSncFlwNw 0 0 0 0 0 0 0 1 0 0 0 0
1ud1jmxmhafWrrP1FbHCgyybbyw 1 0 0 0 0 0 0 0 0 0 0 0
1udERAnc6pURTnip0Nqfa5pQj6M 0 0 0 0 0 0 0 1 0 0 1 0
1udXHe8n9yEOsW31HoXkj7sqoZS 0 1 0 0 0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