Given these 2 dataframes:
A = pd.DataFrame([[1, 5, 2, 8, 2], [2, 4, 4, 20, 2], [3, 3, 1, 20, 2], [4, 2, 2, 1, 0],
[5, 1, 4, -5, -4], [1, 5, 2, 2, -20], [2, 4, 4, 3, 0], [3, 3, 1, -1, -1],
[4, 2, 2, 0, 0], [5, 1, 4, 20, -2]],
columns=["A", "B", "C", "D", "E"],
index=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
B = pd.DataFrame([[1, 5, 2, 8, 2], [2, 4, 4, 20, 2], [3, 3, 1, 20, 2], [4, 2, 2, 1, 0]],
columns=["A", "B", "C", "D", "E"],
index=[1, 2, 3, 4])
Is there a pythonic way to get C = A - B, and the output be:
A B C D E
5 5 1 4 -5 -4
6 1 5 2 2 -20
7 2 4 4 3 0
8 3 3 1 -1 -1
9 4 2 2 0 0
10 5 1 4 20 -2
If the index makes sense, you can subset based on the index:
A[~A.index.isin(B.index)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With