There are two pandas dataframes I have which I would like to combine with checking of two conditionals.
Dataframe1:
import pandas as pd
data = [['Z085', '2020-08', 1.33], ['Z086', '2020-08', 1.83], ['Z086', '2020-09', 1.39]]
df1 = pd.DataFrame(data, columns = ['SN', 'Date', 'Value'])
Dataframe2:
data = [['Z085', '2020-08', 0.34], ['Z085', '2020-09', 0.83], ['Z086', '2020-09', 0.29]]
df2 = pd.DataFrame(data, columns = ['SN', 'Date', 'ValueX'])
df2
I would like to merge or append or join them in order to get the folowing dataframe: The values ("Value" and "ValueX") are being add if both "SN" and "Date" are equal.
I am not sure, if a new dataframe is required or to map the df2 to the df1.
This is what i have tried:
df1['ValueX'] = df1[('Date', 'SN')].map(df2_mean.set_index('Date', 'SN')['ValueX'])
With one conditional (for example: Date) it works ok, but i am not able to set up two conditionals.