search
Search
Login
Unlock 100+ guides
menu
menu
web
search toc
close
Comments
Log in or sign up
Cancel
Post
account_circle
Profile
exit_to_app
Sign out
What does this mean?
Why is this true?
Give me some examples!
search
keyboard_voice
close
Searching Tips
Search for a recipe:
"Creating a table in MySQL"
Search for an API documentation: "@append"
Search for code: "!dataframe"
Apply a tag filter: "#python"
Useful Shortcuts
/ to open search panel
Esc to close search panel
to navigate between search results
d to clear all current filters
Enter to expand content preview
icon_star
Doc Search
icon_star
Code Search Beta
SORRY NOTHING FOUND!
mic
Start speaking...
Voice search is only supported in Safari and Chrome.
Navigate to

Pandas DataFrame | eq method

schedule Aug 12, 2023
Last updated
local_offer
PythonPandas
Tags
mode_heat
Master the mathematics behind data science with 100+ top-tier guides
Start your free 7-days trial now!

Pandas DataFrame.eq(~) method returns a DataFrame of booleans where True indicates an entry that is equal to the specified value.

WARNING

Missing values (NaN) are considered to be distinct, that is, NaN==NaN will evaluate to False.

Parameters

1. otherlink | scalar or sequence or Series or DataFrame

The value to check for equality.

2. axislink | string or int | optional

Whether to perform the comparison along the columns or the rows:

Axis

Description

"index" or 0

Compare each column.

"columns" or 1

Compare each row.

By default, axis=1.

3. level | int or string | optional

The levels to perform comparison on. This is only relevant if your source DataFrame is a multi-index.

Return Value

A DataFrame of booleans.

Examples

Consider the following DataFrame:

df = pd.DataFrame({"A":[1,2], "B":[3,4]})
df
A B
0 1 3
1 2 4

Element-wise comparisons

To check which values in df equal 3:

df.eq(3)
A B
0 False True
1 False False

Row-wise comparisons

To perform row-wise comparisons, pass an array-like structure like follows:

df.eq([1,2]) # axis=1
A B
0 True False
1 False False

Here, we are comparing each row of the source DataFrame with [1,2]. This means that we are performing the following pair-wise comparisons:

(row one) [1,3] == [1,2] = [True, False]
(row two) [2,4] == [1,2] = [False, False]

Column-wise comparisons

For your reference, we show the df here again:

df
A B
0 1 3
1 2 4

To perform column-wise comparisons, pass an array-like structure and set axis=0:

df.eq([1,2], axis=0)
A B
0 True False
1 True False

Here, we are comparing each column of the source DataFrame with [1,2]. This means that we are performing the following pair-wise comparisons:

(column A) [1,2] == [1,2] = [True, True]
(column B) [3,4] == [1,2] = [False, False]
robocat
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
thumb_up
thumb_down
Comment
Citation
Ask a question or leave a feedback...
thumb_up
1
thumb_down
0
chat_bubble_outline
0
settings
Enjoy our search
Hit / to insta-search docs and recipes!