How to select element locations from two Pandas dataframes of identical shape, where the values match within a certain range?
<p>How to select element locations from two Pandas dataframes of identical shape, where the values match within a certain range? A code to do this might be simple to write, but I want to know if there is a smart way to make this conditional selection (like loc) with Pandas data frames as I will need it for large image files and I believe Pandas is generally quick and efficient. </p>

<p>I need more information about </p>

<blockquote>
  <p>he values match within a certain range</p>
</blockquote>

<p>But this is an example selecting values that are the same in the two <code>DataFrame</code>. By replacing the test by any other test, you could reach your goals.</p>

<pre><code># Test data
df1 = DataFrame({'col1':[1.2, 3.2, 4.2], 'col2':[0, 2.1, 4.8], 'col3': [2.0, 0, 8.2]})
df2 = DataFrame({'col1':[2.2, 3.2, 4.2], 'col2':[4.1, 0, 4.8], 'col3': [2.0, 4.7, 8.2]})

# df1
#    col1  col2  col3
# 0   1.2   0.0   2.0
# 1   3.2   2.1   0.0
# 2   4.2   4.8   8.2

# df2
#    col1  col2  col3
# 0   2.2   4.1   2.0
# 1   3.2   0.0   4.7
# 2   4.2   4.8   8.2

# Assuming the two DataFrame have the same index and columns you can simply do that

df2[df2 == df1]

#    col1  col2  col3
# 0   NaN   NaN   2.0
# 1   3.2   NaN   NaN
# 2   4.2   4.8   8.2
</code></pre>

python pandas dataframe