0

I have two dataframes: df1 and df2

df1:

                       date   
0       2002-06-02 00:00:00       
1       2002-06-02 06:00:00           
2       2002-06-02 12:00:00  
3       2002-06-02 18:00:00           
4       2002-06-03 00:00:00   
5       2002-06-03 06:00:00           
6       2002-06-03 12:00:00            

df2:

                       date  total  
0       2002-06-02 00:00:00  NaN       
1       2002-06-03 00:00:00  120000       
2       2002-06-04 00:00:00  NaN         

Desired output:

    date  total  
0       2002-06-02 00:00:00  NaN       
1       2002-06-02 06:00:00  NaN       
2       2002-06-02 12:00:00  NaN   
3       2002-06-02 18:00:00  NaN 
4       2002-06-03 00:00:00  120000         
5       2002-06-03 06:00:00  NaN 
6       2002-06-03 12:00:00  NaN          

Here is the code that I have attempted:

df1['total'] = df1['date'].map(df2.set_index('date')['total'])

However, what I get as an output is this....

                       date  total  
0       2002-06-02 00:00:00  NaN       
1       2002-06-02 00:00:00  NaN       
2       2002-06-02 00:00:00  NaN   
3       2002-06-02 00:00:00  NaN 
4       2002-06-03 00:00:00  120000         
5       2002-06-03 00:00:00  120000 
6       2002-06-03 00:00:00  120000

I am new to python and hope someone can help me resolve this. Thanks

Tom Ron
  • 5,906
  • 3
  • 22
  • 38
windwalker
  • 359
  • 4
  • 14

0 Answers0