title: pandas drops index index on merge in Python?
body: <p>I am merging two dataframes using <code>merge(..., how='left')</code> since I want to retain only entries that match up with the "left" dataframe. The problem is that the merge operation seems to drop the index of my leftmost dataframe, shown here:</p>
  
  <pre><code>import pandas
  df1 = pandas.DataFrame([{"id": 1,
                           "name": "bob"},
                          {"id": 10,
                           "name": "sally"}])
  df1 = df1.set_index("id")
  df2 = pandas.DataFrame([{"name": "bob",
                           "age": 10},
                          {"name": "sally",
                           "age": 11}])
  
  print "df1 premerge: "
  print df1
  df1 = df1.merge(df2, on=["name"],
                  how="left")
  print "merged: "
  print df1
  # This is not "id"
  print df1.index
  # And there's no "id" field
  assert ("id" in df1.columns) == False
  </code></pre>
  
  <p>Before the merge, <code>df1</code> was indexed by <code>id</code>. After the merge operation, there's just the default numeric index for the merged dataframe and the <code>id</code> field was dropped. How can I do this kind of merge operation but retain the index of the leftmost dataframe?  </p>
  
  <p>To clarify: I want all the columns of <code>df2</code> to be added to every entry in <code>df1</code> that has the matching <code>id</code> value. If an entry in <code>df2</code> has an <code>id</code> value not in <code>df1</code>, then that shouldn't be merged in (hence the <code>how='left'</code>).</p>
  
  <p><strong>edit</strong>: I could as a hack do: <code>df1.reset_index()</code> but merging and then set the index again, but I prefer not to if possible, it seems like merge shouldn't have to drop the index. thanks.</p>