Skip to content
Advertisement

How to merge 2 dataframe by date and time in python pandas?

I want to match certain parts of 2 dataframes by date and time and merge them into one of them. But my code is not working. I have 2 dataframe df and df2. First is df and second is df2. What can I do for this? I want to add Weather, Temp, Feels and after that to df.

enter image description here enter image description here

here is the text verison of datafreames. It’s just a sample because they are too big

JavaScript
JavaScript
JavaScript

Advertisement

Answer

  • Creation of the first dataframe:

    JavaScript
    JavaScript
  • Creation of the second dataframe:

    JavaScript
    JavaScript
  • Merge through pandas.merge_asof:

    JavaScript
    JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement