0

I'm trying to find all rows where the timestamps from one dataframe are the same as the timestamps from another dataframe. The problem is that the two dataframes have different lengths AND when they have the same timestamp, those two rows will be from different rows in their respective dataframes. The gist is that I want to compare a timestamp from one dataframe to every row of another dataframe.

I used df1[df1.eq(df2) == True] but this relies on the timestamps that are the same having the same index value. The eq method returns False even if two of the same timestamps exist in both dataframes but are on different rows.

Ex. df1

0   2000-01-01 00:00:00

1   2000-01-02 00:00:00

2   2000-01-03 00:00:00

df2

0    2000-01-02 00:00:00

1    2000-01-03 00:00:00

2    2000-01-04 00:00:00

df1.eq(df2) returns

0    False

1    False

2    False

even though 2000-01-02 00:00:00 and 2000-01-03 00:00:00 exist in both the dataframes.

ndhulipala
  • 112
  • 6
Alyssa S
  • 1
  • 2

1 Answers1

1

merge the dataframes and you will know what dates are present in both dataframes:

dates_in_both_dfs = df1.merge(df2, on="date_column", how="inner")["date_column"].tolist()

Depending on your desired output you can add new columns to the dataframes. For example:

df1['repeated_date'] = df["date_column"].isin(dates_in_both_dfs)
100tifiko
  • 361
  • 1
  • 10