Q:

Dataframe Comparison

I have a working brute force nested for loop solution for comparing two dataframes and coming to a working solution.  I'd like to be more efficient. Let's say I have two dataframes per the sample below.  How can I append (as a string) all data from df2 into df1 where df1 does not equal df2.  
import pandas as pd
import numpy as np
df1=pd.DataFrame({'Col1' : ['blue', 2, 3, 4], 'Col2' : [90, 99, 3, 97], 'Col3' : [11, 12, 13, 14]})
df2=pd.DataFrame({'Col1' : ['blue', 2, 3, 6], 'Col2' : [90, 99, 99, 97], 'Col3' : [11, 12, 13, 14]})

I have tried:
np.where(df1.ne(df2),str(df1)+str(df2),0)

Results should be:
array([[0, 0, 0],
       [0, 0, 0],
       [0, '3 99', 0],
       ['4 6', 0, 0]])

This attempt to be more efficient was a memory error nightmare and is wrong. 
Results in the first cell to show 'blue green' or 'blue \n green'.  Anyone have any ideas?  I'll be applying this solution to a several million by 40 dataframe every day and hoping to limit the production time for results.

A:

Given your input:
df1=pd.DataFrame({'Col1' : ['blue', 2, 3, 4], 'Col2' : [90, 99, 3, 97], 'Col3' : [11, 12, 13, 14]})
df2=pd.DataFrame({'Col1' : ['blue', 2, 3, 6], 'Col2' : [90, 99, 99, 97], 'Col3' : [11, 12, 13, 14]})

Create a mask:
mask = df1.ne(df2)

Then... take your df's as strings, and concat the matching elements, fill in the nans, and take the .values, eg:
result = (df1.astype(str)[mask] + ' ' + df2.astype(str)[mask]).fillna(0).values

Gives you:
array([[0, 0, 0],
       [0, 0, 0],
       [0, '3 99', 0],
       ['4 6', 0, 0]], dtype=object)

