Create a Pivot table of a column values both at rows and column and count only the common values between the relation

44 views Asked by At

So I have the data like below:

df = pd.DataFrame({'Customer':'Alan John Mike'.split(' ') * 3,
                   'Price':[111,222,333,444,444,222,666,111,333]})

Souce Data

I want to count the unique matching Price across the customers in 2 * 2 matrix and want the output like below:

enter image description here

I have the pivot function below but it returns just a count across matching Customers:

pvt = pd.pivot_table(df,index=['Customer'],columns=['Customer'], aggfunc={'Price':lambda x: x.nunique()})
0

There are 0 answers