How to compare values in two Pandas Dataframes? Last Updated : 12 Jan, 2022 Comments Improve Suggest changes Like Article Like Report 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: Python3 import pandas as pd # elements of first dataset first_Set = {'Prod_1': ['Laptop', 'Mobile Phone', 'Desktop', 'LED'], 'Price_1': [25000, 8000, 20000, 35000] } # creation of Dataframe 1 df1 = pd.DataFrame(first_Set, columns=['Prod_1', 'Price_1']) print(df1) # elements of second dataset second_Set = {'Prod_2': ['Laptop', 'Mobile Phone', 'Desktop', 'LED'], 'Price_2': [25000, 10000, 15000, 30000] } # creation of Dataframe 2 df2 = pd.DataFrame(second_Set, columns=['Prod_2', 'Price_2']) print(df2) Output: 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 TrueOtherwise, assign the value of False. Python3 import numpy as np # add the Price2 column from # df2 to df1 df1['Price_2'] = df2['Price_2'] # create new column in df1 to # check if prices match df1['Price_Matching'] = np.where(df1['Price_1'] == df2['Price_2'], 'True', 'False') df1 Output: Comment More infoAdvertise with us Next Article How to compare values in two Pandas Dataframes? N nikki2398 Follow Improve Article Tags : Python Python-pandas Python pandas-dataFrame Practice Tags : python Similar Reads How to combine two DataFrames in Pandas? While working with data, there are multiple times when you would need to combine data from multiple sources. For example, you may have one DataFrame that contains information about a customer, while another DataFrame contains data about their transaction history. If you want to analyze this data tog 3 min read How To Compare Two Dataframes with Pandas compare? A DataFrame is a 2D structure composed of rows and columns, and where data is stored into a tubular form. It is mutable in terms of size, and heterogeneous tabular data. Arithmetic operations can also be performed on both row and column labels. To know more about the creation of Pandas DataFrame. He 5 min read How to Subtract Two Columns in Pandas DataFrame? In this article, we will discuss how to subtract two columns in pandas dataframe in Python. Dataframe in use: Method 1: Direct Method This is the __getitem__ method syntax ([]), which lets you directly access the columns of the data frame using the column name. Example: Subtract two columns in Pand 3 min read How to Check the Data Type in Pandas DataFrame? Pandas DataFrame is a Two-dimensional data structure of mutable size and heterogeneous tabular data. There are different Built-in data types available in Python.  Two methods used to check the datatypes are pandas.DataFrame.dtypes and pandas.DataFrame.select_dtypes. Creating a Dataframe to Check Dat 2 min read How to Get the Common Index of Two Pandas DataFrames When working with large datasets in Python Pandas, having multiple DataFrames with overlapping or related data is common. In many cases, we may want to identify the common indices between two DataFrames to perform further analysis, such as merging, filtering, or comparison.This article will guide us 5 min read Like