How to rename a pandas DataFrame index based on a column condition
<p>I have a DataFrame like this:</p>

<pre><code>import pandas as pd
df = pd.DataFrame(data= {"x": [1,2,3,4],"y":[5,6,7,8],"i":["a.0","a.1","a.0","a.1"]}).set_index("i")
df
</code></pre>

<p>Out:</p>

<pre><code>     x  y
i        
a.0  1  5
a.1  2  6
a.0  3  7
a.1  4  8
</code></pre>

<p>and I want to rename the index based on a column condition:</p>

<pre><code>df.loc[df["y"]&gt;6].rename(index=lambda x: x+ "&gt;6" )
</code></pre>

<p>what gives me:</p>

<pre><code>       x  y
i    
a.0&gt;6  3  7
a.1&gt;6  4  8
</code></pre>

<p>I tried it with inplace=True, but it does not work</p>

<pre><code>df.loc[df["y"]&gt;6].rename(index=lambda x: x+ "&gt;6" , inplace=True )
</code></pre>

<p>I only could get it done by resetting the index, changing the i-column-values via apply and set the index again:</p>

<pre><code>df1 = df.reset_index()
df1.loc[df1["y"]&gt;6, "i"] = df1.loc[df1["y"]&gt;6, "i"].apply(lambda x: x+ "&gt;6" )
df1.set_index("i", inplace=True)
df1
</code></pre>

<p>Out:</p>

<pre><code>       x  y
i    
a.0    1  5
a.1    2  6
a.0&gt;6  3  7
a.1&gt;6  4  8
</code></pre>

<p>But this is so complicated. 
Do you know if there is an easier way?</p>