Reputation: 199
I have two dataframes and I have created a "Check" column in second dataframe to check if values in the Total Claims columns are equal. Here are my two dataframes:
Dataframe 1
Dataframe 2
The code that I used to create the "Check" column comparing Total Claims between the two dataframes was:
reported_claims['Check'] = np.where(reported_claims['Total Claims'].reset_index(drop=True) == df['Total Claims'].reset_index(drop=True) , 'TRUE', 'FALSE')
I noticed that the 7th values in two dataframes are both 31.32 but the check columns says False. I was just wondering why is it saying False and how would I fix this problem? Thank you so much for your time!
Upvotes: 0
Views: 3245
Reputation: 9
Use merge command to join two dataframe and add check column to compare two columns
df = pd.merge(left=Dataframe1, right=Dataframe2, left_on='month', right_on='month')
Upvotes: 1
Reputation: 169
The issue arises by comparing two floating point numbers. The general rule for most programming languages (including python) is that you can never check if two floats are exactly equal. You have to instead check if the two values are close. You can do so using the np.isclose(). Check this answer for a reference on how to use it.
Upvotes: 2