'Create count matrix based on two columns and respective range values pandas
I have a dataframe which looks like below,
name,value,id
meanerror,0.55,aa
meanamount,120,aa
meanerror,0.45,bb
meanamount,150,bb
meanerror,0.88,cc
meanamount,110,cc
meanerror,0.1,dd
meanamount,50,dd
I would like to create a matrix from this dataframe like below.
, meanamount, total_y
meanerror,0-100,100-200
0.0-0.5, 1, 1, 2
0.5-1, 0, 2, 2
total_x, 1, 3
what I actually need is, in the matrix, each cell should contain count of ids which has value(from value column) in the range on both x and y axis of the matrix. i.e for example the first cell should contain count of ids with meanamount in range 0-100 and meanerror in range 0.0-5.
I have tried pandas pivot table and crosstab but unsure how to achieve this. Can anyone help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
