0

I have one dataframe_1 as

        date
0 2020-01-01
1 2020-01-02
2 2020-01-03
3 2020-01-04
4 2020-01-05

and another dataframe_2 as

             date source dest     price
634647 2020-09-18    EUR  USD  1.186317
634648 2020-09-19    EUR  USD  1.183970
634649 2020-09-20    EUR  USD  1.183970

I want to merge them on 'date' but the problem is dataframe_1 last date is '2021-02-15' and dataframe_2 last date is '2021-02-01'.

I want the resulting dataframe as

             date source dest     price
634647 2021-02-01    EUR  USD  1.186317
634648 2021-02-02    NaN  NaN  NaN
634649 2021-02-03    Nan  NaN  NaN
...
             date source dest     price
634647 2021-02-13    NaN  NaN  NaN
634648 2021-02-14    NaN  NaN  NaN
634649 2021-02-25    NaN  NaN  NaN

But I am not able to do it using pd.merge, please ignore the indices in the dataframes. Thanks a lot in advance.

2
  • Your question / instructions are not very clear, unfortunately, at least for me. Commented Feb 18, 2021 at 16:43
  • you need to look at and understand the how parameter. Looks like you need left or outer but you have not really stated your requirement Commented Feb 18, 2021 at 18:47

1 Answer 1

1

you can use join to do it.

df1.set_index('date').join(df2.set_index('date'))
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot sos, I was able to solve it using reset_index instead of set index, but your answer got me thinking, once again thanks a lot.

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.