I have two data frames as blows (df5 and dfS), saving air pollution data. Their index is DateTime, as can been seen. In the DateTime index, the second reading is different. So I want to merge them when a date, hour and Minutes of their reading is the same and ignore the second. df5:
dfS:
Below is my code:
dfG=df5.merge(dfS,left_on='Min', right_on='Min' )
dfG['DATETIME'] = dfG.Date "_" dfG.Time
dfG.to_csv('dfG.csv')
dfG.set_index("DATETIME", inplace=True)
#correct the underscores in old datetime format
dfG.index = [" ".join(str(val).split("_")) for val in dfG.index]
as it can be seen the index is not correct because I considered 'Min' as key for joining.
My question is: How to merge these two data frames based on DateTime index ignoring the second.
CodePudding user response:
if the seconds on your timestamp is not important , maybe this can help:
df5.index = df5.index.map(lambda x: x.replace(second=0))