Reduction the Pandas dataframe to other dataframe
<p>I have two data frames and their shapes are (<code>707</code>,<code>140</code>) and (<code>34</code>,<code>98</code>).</p>

<p>I want to minimize the bigger data frame to the small one based on the same index name and column names. </p>

<p>So after the removing additional rows and columns from bigger data frame, in the final its shape should be (<code>34</code>,<code>98</code>) with the same index and columns with the small data frame.</p>

<p>How can I do this in python ? </p>

<p>I think you can select by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.loc.html" rel="nofollow"><code>loc</code></a> <code>index</code> and <code>columns</code> of small <code>DataFrame</code>:</p>

<pre><code>dfbig.loc[dfsmall.index, dfsmall.columns]
</code></pre>

<p>Sample:</p>

<pre><code>dfbig = pd.DataFrame({'a':[1,2,3,4,5], 'b':[4,7,8,9,4], 'c':[5,0,1,2,4]})
print (dfbig)
   a  b  c
0  1  4  5
1  2  7  0
2  3  8  1
3  4  9  2
4  5  4  4

dfsmall = pd.DataFrame({'a':[4,8], 'c':[0,1]})
print (dfsmall)
   a  c
0  4  0
1  8  1

print (dfbig.loc[dfsmall.index, dfsmall.columns])
   a  c
0  1  5
1  2  0
</code></pre>

python pandas dataframe multiple-columns