Pandas Left Merging 'date' Keys With Different Date Formats (not Timestamps)
Hello Stack Overflow community, I am having an issue where Pandas is not understanding my merge conditions. It works with the other 'keys', but breaks as soon as I include the 'Da
Solution 1:
Running the below code before the merge should put the dates into a common format so that the merge works properly.
import time
df['Date']=time.strftime('%Y-%m-%d',time.strptime(df['date'],'%m/%d/%Y'))
df2['Date']=time.strftime('%Y-%m-%d',time.strptime(df2['date'],'%Y-%m-%d'))
It would have been nice to simply change one of the dates, but the python time library adds a leading 0 to the month and date with the %m
and %d
tags. The %-m
and %-d
tags would not add the leading 0s, but they don't work across all systems. See here for more information on that oddity.
Post a Comment for "Pandas Left Merging 'date' Keys With Different Date Formats (not Timestamps)"