0

I have 2 dataframes.

dfA has 848 rows

dfB has 600 rows

Both have Date column as Index.

I want to find the 600 rows in dfA that match the dates in dfB -- dfA should end with 600 rows that match dfB.

Trying something like below but isn't working...

dfA.iloc(dfB.index)
  • Please clarify what you're trying to do, and share example input/output and a [mcve]. In any case, this looks like a duplicate of https://stackoverflow.com/questions/43297589/merge-two-data-frames-based-on-common-column-values-in-pandas – AMC Feb 08 '20 at 17:38

1 Answers1

0

Use DataFrame.reindex:

dfA.reindex(index = dfB.index)

or DataFrame.loc

dfA.loc[dfB.index]

or if that column is not really set as an index you can do:

dfA.set_index('Date').reindex(index = dfB['Date'])
ansev
  • 30,322
  • 5
  • 17
  • 31