I have two data frames with several overlapping indexes and columns.
old = pd.DataFrame(index = ['A', 'B', 'C'], columns = ['k', 'l', 'm'], data = abs(np.floor(np.random.rand(3, 3)*10))) new = pd.DataFrame(index = ['A', 'B', 'C', 'D'], columns = ['k', 'l', 'm', 'n'], data = abs(np.floor(np.random.rand(4, 4)*10)))
I want to calculate the difference between them and try
delta = new - old
This gives a lot of NaN where the indices and columns do not match. I would like to treat the absence of indexes and columns as zero, (old ['n', 'D'] = 0). old will always be a subspace of the new.
Any ideas?
EDIT: I guess I didn't explain it enough. I do not want to populate a delta frame with zeros. I want to handle the missing indexes and columns old as if they were zeros. Then I got the value in the new ['n', 'D'] in delta instead of NaN.
source share