ne() Function Of Pandas DataFrame Class

The ne() method of pandas DataFrame class implements the "not equal to" operator(element-wise). The Python example code checks two DataFrame instances using ne() and prints the results.

Dataframe Binaryoperatorfunctions Updated 24 Jul 2019 1 min read

Overview

  • The ne() function implements the binary operation "Not Equal To"(!=) for a pandas DataFrame instance to be compared with another DataFrame.
  • The result of the (un)equality check by ne() method is returned as a DataFrame.
  • The returned DataFrame instance contains Boolean values denoting the results of the equality test for the elements present in two DataFrame instances.

Example

python
# Python example program that checks elements from two pandas DataFrame instances for

# unequality

import pandas as pd

d1 = [(10, 20, 30),

      (40, 50, 60),

      (70, 80, 90)];

d2 = [(10, 15, 30),

      (20, 25, 50),

      (70, 75, 90)];

dataFrame1 = pd.DataFrame(data=d1);

dataFrame2 = pd.DataFrame(data=d2);

# Check which dataframe elements are not equal

result = dataFrame1.ne(dataFrame2);

# Print first data frame

print("Dataframe1:");

print(dataFrame1);

# Print second data frame

print("Dataframe2:");

print(dataFrame2);

# Print Dataframe1 != Dataframe2

print("Result of dataFrame1.ne(dataFrame2):");

print(result);

Output

Output
Dataframe1:

    0   1   2

0  10  20  30

1  40  50  60

2  70  80  90

Dataframe2:

    0   1   2

0  10  15  30

1  20  25  50

2  70  75  90

Result of dataFrame1.ne(dataFrame2):

       0     1      2

0  False  True  False

1   True  True   True

2  False  True  False