Your code failed because distdf.loc[i] == distdf.loc[i+1]
attempts
to compare whole rows, i.e. two Series objects.
Some impovement would be if you wrote:
if distdf.loc[i, 'DISTINGUISH']==distdf.loc[i+1, 'DISTINGUISH']:
,
i.e. compared DISTINGUISH elements in each row (current and the next).
But this code would also fail on the last turn of the loop, because
when you "stay" on the last row, there is no next row, so then
KeyError exception is raised.
There is a simpler, more pandasonic approach to get a list of your values,
without any loop.
Assume that your DataFrame (distdf) contains:
DISTINGUISH
0 1
1 1
2 2
3 2
4 3
5 3
6 32
7 32
8 33
9 33
10 34
11 34
As you want to operate on its only column, to keep the code short,
let's save it under col0:
col0 = distdf.iloc[:, 0]
Then, to get your list of values, without any loop, run:
np.where(col0 == col0.shift(-1), 'true', 'no')
The result, for the above data, is:
array(['true', 'no', 'true', 'no', 'true', 'no', 'true', 'no', 'true',
'no', 'true', 'no'], dtype='<U4')