Problem
df1 = pd.DataFrame({"A":[12, 4, 5, 44, 1],
"B":[5, 2, 54, 3, 2] })
df2 = pd.DataFrame({"A":[20, 16, 7, 3, 8],
"B":[14, 3, 17, 2, 6]})
Given two dataframes, df1
and df2
, I want to create a third dataframe, df3
which contains the maximum values of the two dataframes.
df3 =pd.DataFrame({"A":[20, 16, 7, 44, 8],
"B":[14, 3, 54, 3, 6]})
Attempt
I created two temp dataframes with both columns of A from df1
and df2
into a numpy
array, then found each maximum value. The same process was repeated for B. I then combined both arrays for A and B to get df3
. However, I feel this is not elegant and I want a more efficient method for accomplishing this task.
Thank you @beny @Romero_91 @cameron-riddell ... your solutions are very elegant and simpler than mine! I knew I was missing something!!