0

I need your help. I have 2 DataFrame, Table A and Table B. I need to find the date that is in Table A in Table B and add a column with the values of the VALUE2 AND VALUE3 columns, leaving VALUE 1 behind. The output is Table C.

I mean there are many columns

Table A

DATE           NAME    EDAD  
2019-07-18      KAT     12     
2019-07-19      FEP     13     

Table B

DATE          VALUE1 VALUE2 VALUE3
2019-07-16      10      20     30
2019-07-17      11      22     33
2019-07-18      10      20     30
2019-07-19      11      22     33

Table C

DATE           NAME    EDAD  VALUE2 VALUE3
2019-07-18      KAT     12     20     30
2019-07-19      FEP     13     22     33

thanks!
Katherine
  • 41
  • 4
  • 1
    https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.merge.html start here, you will find your way – ombk Nov 25 '20 at 01:29
  • 1
    Does this answer your question? [Merge two dataframes by index](https://stackoverflow.com/questions/40468069/merge-two-dataframes-by-index) – ombk Nov 25 '20 at 01:30
  • No, I need to find the date and give me the data corresponding to that date – Katherine Nov 25 '20 at 01:33
  • `df3 = pd.merge(df1, df2, left_index=True, right_index=True)` try this code – ombk Nov 25 '20 at 01:34

1 Answers1

1

Try:

df1.merge(df2,on='DATE', how='left')[['DATE','NAME','EDAD','VALUE2','VALUE3']]

df1 is Table A and df2 is Table B

Prints:

         DATE NAME  EDAD  VALUE2  VALUE3
0  2019-07-18  KAT    12      20      30
1  2019-07-19  FEP    13      22      33
sharathnatraj
  • 1,294
  • 3
  • 11