title: How to sum columns from three different dataframes with a common key
body: <p>I am reading in an excel spreadsheet about schools with three sheets as follows.</p>
  
  <pre><code>import sys
  import pandas as pd
  inputfile = sys.argv[1]
  xl = pd.ExcelFile(inputfile)
  print xl.sheet_names
  df1 = xl.parse(xl.sheet_names[0], skiprows=14)
  df2 = xl.parse(xl.sheet_names[1], skiprows=14)
  df3 = xl.parse(xl.sheet_names[2], skiprows=14)
  df1.columns = [chr(65+i) for i in xrange(len(df1.columns))]
  df2.columns = df1.columns
  df3.columns = df1.columns
  </code></pre>
  
  <p>The unique id for each school is in column 'D' in each of the three dataframes. I would like to make a new dataframe which has two columns. The first is the sum of column 'G'  from df1, df2, df3 and the second is the sum of column 'K'  from df1, df2, df3.  In other words, I think I need the following steps.</p>
  
  <ol>
  <li>Filter rows for which unique column 'D' ids actually exist in all three dataframes. If the school doesn't appear in all three sheets then I discard it.</li>
  <li>For each remaining row (school), add up the values in column 'G' in the three dataframes.</li>
  <li>Do the same for column 'K'.</li>
  </ol>
  
  <p>I am new to pandas but how should I do this?  Somehow the unique ids have to be used in steps 2 and 3 to make sure the values that are added correspond to the same school.</p>
  
  <hr>
  
  <p>Attempted solution</p>
  
  <pre><code>df1 = df1.set_index('D')
  df2 = df2.set_index('D')
  df3 = df3.set_index('D')
  df1['SumK']= df1['K'] +  df2['K'] + df3['K']
  df1['SumG']= df1['G'] +  df2['G'] + df3['G']
  </code></pre>