I have a matrix with the grades from a class for different years(rows for years and columns for grades). What I want is to build a transition matrix with the change between years.
For instance, I want year t-1 on the y-axis and year t on the x-axis and then I want a transition matrix with the difference in the number of people with grade A between year t-1 and t, grade B between year t-1 and t, and so on. And then a second transition matrix with the proportions, for example: - Between year t-1 and t there z% more/less people with grade A/B/C/D/F.
Obviously the moest import part is the diagonal which would represent the change for the same grade for different years.
I want this to be done in Python.
Thank you very much, I hope everything is clear.
Result example: enter image description here
You can use pandas library with
df.diff
. numpy can generate the matrix of all possible differences usingnp.subtract.outer
. below is an example.each row here in
df_diff
is the difference between current row and the preceding one from original dfplot this matrix using
matshow
frommatplotlib