I would like to merge two data frames, and keep the index from the first frame as the index on the merged dataset. However, when I do the merge, the resulting DataFrame has integer index. How can I specify that I want to keep the index from the left data frame?
In [441]: a=DataFrame(data={"col1": [1,2,3], 'to_merge_on' : [1,3,4]}, index=["a","b","c"])
In [442]: b=DataFrame(data={"col2": [1,2,3], 'to_merge_on' : [1,3,5]})
In [443]: a
Out[443]:
col1 to_merge_on
a 1 1
b 2 3
c 3 4
In [444]: b
Out[444]:
col2 to_merge_on
0 1 1
1 2 3
2 3 5
In [445]: a.merge(b, how="left")
Out[445]:
col1 to_merge_on col2
0 1 1 1
1 2 3 2
2 3 4 NaN
In [446]: _.index
Out[447]: Int64Index([0, 1, 2])
EDIT: Switched to example code that can be easily reproduced