Reputation: 372
I have multiple dataframes with different data but all have a date column. I need to make sure each dataframe's date column exactly matches(data/row etc) something like:
if df1['Date'] == df2['Date'] == df3['Date']:
I cannot for the life of me figure this out.
I was thinking just comparing them and producing a true/false and checking that
(np.where(df1['Date'] == df2['Date'], 'True', 'False')
but this seems inefficient.
any help is appreciated.
Thanks in advance.
EDIT: Shubham pointed out to use
df1['Date'] == df2['Date']
however this produces an error
if df1['Date'] == df2['Date']:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
I looked into it and when using and/or you can just change to &/| to avoid error but I do not know how to make this if statement work.
Thanks
Upvotes: 1
Views: 48
Reputation: 181
for the error you are getting use .all()
if (df1['Date'] == df2['Date']).all():
Using np.where is fine, you can also use isin: df1['Date'].isin(df2['Date'])
and with value_counts check if there was any date that did not match
False not in df1['Date'].isin(df2['Date']).value_counts()
Upvotes: 1