Identifying overlapping rows in multiple dataframes
<p>I have two dataframes like </p>

<p>df1</p>

<pre><code>Time      accler
19.13.33  24
19.13.34  24
19.13.35  25
19.13.36  27
19.13.37  25
19.13.38  27
19.13.39  25
19.13.40  24
</code></pre>

<p>df2</p>

<pre><code> Time      accler
19.13.29  24
19.13.30  24
19.13.31  25
19.13.32  27
19.13.33  25
19.13.34  27
19.13.35  25
19.13.36  24
</code></pre>

<p>These two data frames overlap over column time from 19.13.33 to 19.13.36. So when ever there is a overlap  I wanted only the dataframe which consists of the overlapped rows</p>

<p>expected output</p>

<p>df1</p>

<pre><code> Time      accler
19.13.33  24
19.13.34  24
19.13.35  25
19.13.36  27
</code></pre>

<p>df2</p>

<pre><code>Time      accler
19.13.33  25
19.13.34  27
19.13.35  25
19.13.36  24
</code></pre>

<p>or I can also have a <code>concat</code> of the dataframes which will be helpful for further processing. </p>

<p>I tried <code>merge</code> but did not work as the dataframes are created dynamically depending on the number of csv files. I tried concatenating first all the dataframes and tried to iterate over the rows but did not find a way.</p>

<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>, default parameter <code>how='inner'</code> can be omited:</p>

<pre><code>df = pd.merge(df1, df2, on='Time')
print (df)
       Time  accler_x  accler_y
0  19.13.33        24        25
1  19.13.34        24        27
2  19.13.35        25        25
3  19.13.36        27        24

df1 = df[['Time','accler_x']].rename(columns={'accler_x':'accler'})
print (df1)
       Time  accler
0  19.13.33      24
1  19.13.34      24
2  19.13.35      25
3  19.13.36      27

df2 = df[['Time','accler_y']].rename(columns={'accler_y':'accler'})
print (df2)
       Time  accler
0  19.13.33      25
1  19.13.34      27
2  19.13.35      25
3  19.13.36      24
</code></pre>

<p>If you need <code>merge</code> multiple <code>DataFrames</code> use <a href="https://docs.python.org/3.0/library/functools.html#functools.reduce" rel="nofollow"><code>reduce</code></a>:</p>

<pre><code>#Python 3
import functools

df = functools.reduce(lambda x,y: x.merge(y,on=['Time']), [df1, df2])

#python 2
df = reduce(lambda x,y: x.merge(y,on=['Time']), [df1, df2])
</code></pre>

python pandas merge inner-join concat