0

I have two dataframes like that :

Dataframe 1

   Date         ID     A
0  21/12/13     0      123
1  21/12/14     1      936
2  21/12/15     2      527
3  21/12/16     3      946

Dataframe 2

   Date         ID     B
0  21/12/16     3      234
1  21/12/17     4      990
2  21/12/18     5      62
3  21/12/19     6      103

I'm looking for this final Dataframe :

   Date         ID     A     B
0  21/12/13     0      123   NaN
1  21/12/14     1      936   NaN
2  21/12/15     2      527   NaN
3  21/12/16     3      946   243
4  21/12/17     4      NaN   990
5  21/12/18     5      NaN   62
6  21/12/19     6      NaN   103

Do you know how to have this result ? I want to have a unique line when the two keys value Date + ID are present in dataframe A and B.

I tried some things with concatenate with Pandas but it failed.

Thanks in advance !

Alan CUZON
  • 35
  • 4
  • 1
    Did you try [`merge`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.merge.html)? I see you included merge in your question tags. Look at the option how='outer'. – SomeDude Apr 27 '22 at 12:55
  • `df1.merge(df2,on=['ID','Date'],how='outer')` something like that ? However it's not working, when I use info() method on df1 and df2, there is respectively 7 lines and 3090 lines. On the merge df, I have only 790 lines ... – Alan CUZON Apr 27 '22 at 12:58
  • Try just `on=['ID']` – SomeDude Apr 27 '22 at 13:15
  • Why I put juste on 'ID' I have two Date Columns, so I need two combine Date & ID. Moreover, I forgot to preciser that I have in date the date + the hour. – Alan CUZON Apr 27 '22 at 13:34

0 Answers0