I have two data frames I am trying to merge using pandas.
lu_3
Site SurveyDate TripDate
003L 1990-09-28 1990-06-10
065r 2008-04-03 2008-03-28
data
Site SurveyDate
003L 1990-09-28
065r 2008-04-03
I am trying to merge lu_3
to populate data
with a TripDate
. data
has been subsetted for ease of reading, but contains more columns than shown. Both data frames are using Site
as the index.
I have tried:
tmp = data.merge(lu_3,left_index=True,right_index=True,how='left', on=['SurveyDate'])
But that returns a NaT
for the trip date.
Checking the data types yields:
lu_3.dtypes
Out[111]:
SurveyDate datetime64[ns]
TripDate datetime64[ns]
dtype: object
data.dtypes
Out[114]:
SurveyDate datetime64[ns]
EDIT
I have reset the indicies on data
and lu_3
and tried to merge using:
tmp = tmp_data.merge(lu_3,on=['Site','SurveyDate'], how='left').set_index('Site')
But I am still getting NaT
for TripDate
on tmp
.