How to compare values in two Pandas Dataframes?
Let’s discuss how to compare values in the Pandas dataframe. Here are the steps for comparing values in two pandas Dataframes:
Step 1 Dataframe Creation: The dataframes for the two datasets can be created using the following code:
Step 2 Comparison of values: You need to import numpy for the successful execution of this step. Here is the general template to perform the comparison:
df1[‘new column for the comparison results’] = np.where(condition, ‘value if true’, ‘value if false’)
Example: After execution of this code, the new column with the name Price_Matching will be formed under df1. Columns result will be displayed according to the following conditions:
- If Price_1 is equal to Price_2, then assign the value of True
- Otherwise, assign the value of False.