Thank you very much scidam for your reply. Actually i am reading 2 csv files which results 2 different dataframes df1 & df2. Well, df1 consists monthly data while df2 consists the information about the check performed on particular user.So, I used second condition because i want to extract all the prior records of a matched consumers from the date mentioned in df2.
(Jul-25-2019, 11:51 PM)scidam Wrote: Something wrong with this code.df1
anddf2
are not Pandas data frames,
they are Python dictionaries.
I don't understand a second condition, are you requiring thatdf1.Date
date is greater (later)
than at least one date indf2.Date
? These dataframes have non-equal sizes, so we cannot perform
elementwise 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]