I have two dataframes, A and B. A and B have the same indices and the same column names. However, their entries are different (a jumble of values and NaN).
I want to merge both A and B into another dataframe C with the same indices and columns.
Let's take A.iloc[1,2], the first row and third column entry of A for example. If that entry in A is NaN, but in B it is 99, I'd like C.iloc[1,2] to be 99. If they're both NaN, then the result will be NaN.
If they're both values, say 23 and 99, i'd like the merge to result in the larger number (99), but I need to flag the index as erroneous.
What I've done:
Wrote a for loop using the rows and columns, to match between both dataframes. If an entry is more than 0 in A and more than 0 in B, for example, then I store the index of the entry in a list and append the larger value in C. This is horrible inefficient and I'd like to use a better method. (plus it failed because I'm a horrible programmer)
Tried using pandas.merge. I don't particularly understand the merging process, but I've tried a few ways like
pd.merge(A, B, left_on = A.index, right_on = B.index, how = 'outer', indicator = True)for example. It returned me a dataframe with even more rows and double the columns with x and y appended to the end of their names.
Any ideas?