Comparing different dataframe indexes

I have two dataframes, both with datetime indexes, one of length 3153 and the other is 3128. What I am looking to do is to drop the dates (rows) from the larger dataframe so that I can combine the the two df's together for a machine learning problem. Here are the dataframes:

             ADP ConsSent USCPI_mom  ... EU_SERPMI EU_UNEMP EU_ZEW
2009-01-01  -435     60.1       0.1  ...      42.5      7.7  -46.1
2009-01-02  -435     60.1       0.1  ...      42.5      7.7  -46.1
2009-01-05  -435     60.1       0.1  ...      42.5      7.7  -46.1
2009-01-06  -435     60.1       0.1  ...      42.1      7.7  -46.1
2009-01-07  -635     60.1       0.1  ...      42.1      7.7  -46.1
...          ...      ...       ...  ...       ...      ...    ...
2021-01-26   -75     80.7         0  ...      46.4      8.3   58.3
2021-01-27   -75     80.7         0  ...      46.4      8.3   58.3
2021-01-28   -75     80.7         0  ...      46.4      8.3   58.3
2021-01-29   -75       79         0  ...      46.4      8.3   58.3
2021-02-01   -75       79         0  ...      46.4      8.1   58.3

[3153 rows x 27 columns]

            Close       Low
Date                          
2009-01-01  1.399894  1.395498
2009-01-02  1.392292  1.384294
2009-01-05  1.364592  1.355601
2009-01-06  1.351004  1.331806
2009-01-07  1.361100  1.343725
...              ...       ...
2021-01-26  1.214624  1.210844
2021-01-27  1.216299  1.206200
2021-01-28  1.210507  1.208240
2021-01-29  1.212004  1.209599
2021-02-01  1.212386  1.206913

[3128 rows x 2 columns]

Now imagine they are named df1 & df2. df1 holds all my economic fundamental data and df2 holds EUR/USD exchange rate data. How can I get these two dataframes combined? Appreciate all the help I can get, many thanks!

1 answer

  • answered 2021-07-27 17:03 Da Song

    something like this will do:

    df = df2.merge(df1, how='inner', left_index=True, right_index=True)
    

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum