Dataset
x y a
1 3 0
1 1 0
1 2 0
3 6 0
5 3 1
1 5 0
1 7 0
1 6 0
1 4 0
Visualization
grid size= 8 x 12
Pivot_table
X = df.pivot(index='x',columns='y',values='a').values
X[np.isnan(X)] = 0
array([[0., 0., 1., 0., 1., 0., 0., 0.],
[0., 1., 0., 0., 1., 0., 1., 0.],
[0., 0., 0., 0., 1., 0., 0., 0.],
[0., 1., 1., 1., 0., 1., 0., 0.],
[0., 0., 0., 1., 0., 0., 0., 0.],
[0., 0., 0., 0., 0., 1., 0., 0.],
[0., 0., 0., 0., 0., 0., 0., 1.],
[0., 0., 0., 0., 1., 0., 0., 0.]])
here pivot table size is (8, 8) but I want to have (8 , 12) the empty rows are excluded in the pivot table.
