Jul-25-2019, 11:51 PM
Something wrong with this code.
they are Python dictionaries.
I don't understand a second condition, are you requiring that
than at least one date in
elementwise comparison.
Nevertheless, try the following, this is probably is what you are looking for:
df1
and df2
are not Pandas data frames, they are Python dictionaries.
I don't understand a second condition, are you requiring that
df1.Date
date is greater (later)than at least one date in
df2.Date
? These dataframes have non-equal sizes, so we cannot performelementwise comparison.
Nevertheless, try the following, this is probably is what you are looking for:
import pandas as pd df1 = pd.DataFrame({'Consumer_No' :[1011,1012,1013,1014,1011,1012,1013,1014,1011,1012,1013,1014,1011,1012,1013,1014], 'Date':['31/01/2019','31/01/2019','31/01/2019','31/01/2019','28/02/2019','28/02/2019','28/02/2019','28/02/2019','31/03/2019','31/03/2019','31/03/2019','31/03/2019','30/04/2019','30/04/2019','30/04/2019','30/04/2019'] }) df2 = pd.DataFrame({'Consumer_No' : [1013,1011],'Date':['24/03/2019','29/04/2019']}) df1.Date =pd.to_datetime(df1.Date) df2.Date =pd.to_datetime(df2.Date) first_condition = df1.Consumer_No.isin(df2.Consumer_No) second_condition = df1.Date > min(df2.Date) result = df1.loc[first_condition & second_condition]