I have two DataFrames
of pandas
with Fechas
and Datos
:
df_A = pd.DataFrame({
'Fecha': ['15/12/2018', '16/12/2018', '18/12/2018'],
'Datos_A': [1, 5, 9]
})
df_B = pd.DataFrame({
'Fecha': ['15/12/2018', '16/12/2018', '17/12/2018', '19/12/2018'],
'Datos_B': [7, 5, 3, 4]
})
I convert the dates to the datetime
format.
df_A.Fecha = pd.to_datetime(df_A.Fecha)
df_B.Fecha = pd.to_datetime(df_B.Fecha)
df_A
Datos_A Fecha
0 1 15/12/2018
1 5 16/12/2018
2 9 18/12/2018
df_B
Datos_B Fecha
0 7 15/12/2018
1 5 16/12/2018
2 3 17/12/2018
3 4 19/12/2018
How can I concatenate both DataFrames
in such a way that the Fecha
column is unified to obtain the following result?
Fecha Datos_A Datos_B
0 2018-12-15 1 7
1 2018-12-16 5 5
2 2018-12-17 NaN 3
3 2018-12-18 9 NaN
4 2018-12-19 NaN 4