Skip to main content
deleted 220 characters in body
Source Link
MaxU - stand with Ukraine
  • 211.7k
  • 37
  • 402
  • 436

what about?

In [9][12]: df.index[df.A == 1]
Out[9]Out[12]: Int64Index([3, 7, 1], dtype='int64')

or (depending on your goals):

In [15]: df.reset_index().index[df.A == 1]
Out[15]: Int64Index([3, 4, 5], dtype='int64')

Demo:

In [7][11]: df
Out[7]Out[11]:
   A
08  0
14  0
26  0
3  1
47  1
51  1
65  2
70  2
82  2
9  2

In [8][12]: df.index[df.A == 11]
Out[8]Out[12]:
0    False
1    False
2    False
3     True
4     True
5     True
6   Int64Index([3, False
7    False
8    False
9    False
Name: A, dtype:1], booldtype='int64')

In [9][15]: df.reset_index().index[df.A == 1]
Out[9]Out[15]: Int64Index([3, 4, 5], dtype='int64')

what about?

In [9]: df.index[df.A == 1]
Out[9]: Int64Index([3, 4, 5], dtype='int64')

Demo:

In [7]: df
Out[7]:
   A
0  0
1  0
2  0
3  1
4  1
5  1
6  2
7  2
8  2
9  2

In [8]: df.A == 1
Out[8]:
0    False
1    False
2    False
3     True
4     True
5     True
6    False
7    False
8    False
9    False
Name: A, dtype: bool

In [9]: df.index[df.A == 1]
Out[9]: Int64Index([3, 4, 5], dtype='int64')

what about?

In [12]: df.index[df.A == 1]
Out[12]: Int64Index([3, 7, 1], dtype='int64')

or (depending on your goals):

In [15]: df.reset_index().index[df.A == 1]
Out[15]: Int64Index([3, 4, 5], dtype='int64')

Demo:

In [11]: df
Out[11]:
   A
8  0
4  0
6  0
3  1
7  1
1  1
5  2
0  2
2  2
9  2

In [12]: df.index[df.A == 1]
Out[12]: Int64Index([3, 7, 1], dtype='int64')

In [15]: df.reset_index().index[df.A == 1]
Out[15]: Int64Index([3, 4, 5], dtype='int64')
Source Link
MaxU - stand with Ukraine
  • 211.7k
  • 37
  • 402
  • 436

what about?

In [9]: df.index[df.A == 1]
Out[9]: Int64Index([3, 4, 5], dtype='int64')

Demo:

In [7]: df
Out[7]:
   A
0  0
1  0
2  0
3  1
4  1
5  1
6  2
7  2
8  2
9  2

In [8]: df.A == 1
Out[8]:
0    False
1    False
2    False
3     True
4     True
5     True
6    False
7    False
8    False
9    False
Name: A, dtype: bool

In [9]: df.index[df.A == 1]
Out[9]: Int64Index([3, 4, 5], dtype='int64')