pandas: renaming column labels in multiindex df
<p>I have a df which looks like this:</p>

<pre><code>import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.random((4,4)))
df.columns = pd.MultiIndex.from_product([['1|mm','2|lll'],['A|ljjh','B|ldjdj']])

       1|mm               2|lll          
     A|ljjh   B|ldjdj    A|ljjh   B|ldjdj
0  0.599202  0.093917  0.582809  0.683346
1  0.902717  0.343215  0.222960  0.238709
2  0.808473  0.290253  0.276607  0.775530
3  0.197891  0.505197  0.243890  0.011838
</code></pre>

<p>I would like to split the column labels for each level like so:</p>

<pre><code>columnlabel.split("|")[0]
</code></pre>

<p>I'm not sure what the best method to do this? should I create a new list and assign that to df.columns or can I do it inplace??</p>

<p>expected output</p>

<pre><code>     1                   2          
     A       B         A         B
0  0.599202  0.093917  0.582809  0.683346
1  0.902717  0.343215  0.222960  0.238709
2  0.808473  0.290253  0.276607  0.775530
3  0.197891  0.505197  0.243890  0.011838
</code></pre>