0

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:

enter image description here

dfS:

enter image description here

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.

DfG: enter image description here

My question is: How to merge these two data frames based on DateTime index ignoring the second.

1
  • 1
    split seconds from there and merge it without seconds. Commented Oct 10, 2021 at 7:58

1 Answer 1

1

if the seconds on your timestamp is not important , maybe this can help:

df5.index = df5.index.map(lambda x: x.replace(second=0))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.