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>I am not sure for the specific example you showed. Anyway, you could do it in a more simple way:</p>

<pre><code>indexes = [i-1 for i,x in enumerate(pId) if x == 'None']
</code></pre>

python pandas indexing shift