import pandas as pd
dt = pd.DataFrame({
'name' : ['o', 'a', 'x'],
'mark' : [7, 4, 10]
})
Why does it return False
when I write
dt.iloc[1] is dt.iloc[1]
or dt.iloc[1,2] is dt.iloc[1,2]
?
Thanks!
CodePudding user response:
Use equals
method to compare Series
data in pandas
also you can refer method Here!
import pandas as pd
dt = pd.DataFrame({
'name' : ['o', 'a', 'x'],
'mark' : [7, 4, 10]
})
dt.iloc[1].equals(dt.iloc[1])
Output:
True
CodePudding user response:
dt.iloc[1]
creates a Series that is a copy of the original, so you're asking if two different things you create are the same thing, which they are not.
If I do:
x = dt.iloc[1]
print(x is x)
y = dt.iloc[1]
print(x is y)
Output:
True
False
See Bhavya's answer for how to properly compare Series.