Index values of specific rows in python
<p>I am trying to find out Index of such rows before "None" occurs.</p>

<pre><code>pId=["a","b","c","None","d","e","None"]
df = pd.DataFrame(pId,columns=['pId'])

              pId
0               a
1               b
2               c
3            None
4               d
5               e
6            None

df.index[df.pId.eq('None') &amp; df.pId.ne(df.pId.shift(-1))]
</code></pre>

<p>I am expecting the output of the above code should be</p>

<pre><code>Index([2,5])
</code></pre>

<p>It gives me </p>

<pre><code>Index([3,6])
</code></pre>

<p>Please correct me</p>

<p>The problem is that you're returning the index of the "None".  You <em>compare</em> it against the previous item, but you're still reporting the index of the "None".  Note that your accepted answer doesn't make this check.</p>

<p>In short, you still need to plaster a "-1" onto the result of your checking.</p>

python pandas indexing shift