-1

I have the following two dataframe:

df1 (date is not an index, 1200 rows)

date         v1    v2   v3
2014/03/01    5    6    4
2014/03/02    6    6    8
2014/03/03    9    25   20
2014/03/05    9    5    55
2014/03/08    0    2    4

and

df2 (date is not an index, 1400 rows)

date        
2014/03/01  
2014/03/02  
2014/03/03   
2014/03/04
2014/03/05 
2014/03/06 
2014/03/05  
2014/03/08 

I want to merge them, to get this with 1400 rows:

timestamp    v1    v2   v3
2014/03/01    5    6    4
2014/03/02    6    6    8
2014/03/03    9    25   20
2014/03/04    0    0    0         <--------
2014/03/05    9    5    55
2014/03/06    0    0    0         <--------
2014/03/07    0    0    0         <--------
2014/03/08    0    2    4

I used this: merged= pd.merge(df1, df2, on="date"), but I got an empty merged with no row. Why is that? Both date columns in the two dataframes are of type object.

  • For merging, df2 should have the same columns as df1, even if they're empty. Also the dates must be converted to a datetime format. – Trenton McKinney May 23 '22 at 18:56

0 Answers0