title: Renaming and selecting columns simultaneously in pandas
body: <p>I've been trying to select columns and renaming it with <code>pandas</code>. In <code>R's dplyr</code> it is pretty straight forward but when it comes to pandas I could not find a way to do it.</p>
  
  <p>For example </p>
  
  <pre><code>import numpy as np
  import pandas as pd
  np.random.seed(128)
  
  df = pd.DataFrame(np.random.random((5,7)), index=pd.Series(range(1,6), name="week"))
  df
  
               0         1         2    ...            4         5         6
  week                                  ...                                 
  1     0.866637  0.263145  0.131408    ...     0.238924  0.645475  0.790599
  2     0.601442  0.334299  0.119428    ...     0.109724  0.602113  0.251285
  3     0.299681  0.517116  0.715203    ...     0.102088  0.706524  0.985842
  4     0.559079  0.592019  0.741931    ...     0.125672  0.907613  0.573170
  5     0.731224  0.301214  0.066628    ...     0.133776  0.655933  0.423496
  </code></pre>
  
  <p>then trying to change some column names</p>
  
  <pre><code>df.rename(columns={0 : "L",1 : "W",2 : "C1",3 : "C2"},inplace=True)
  </code></pre>
  
  <p>and had to select the columns are interested</p>
  
  <pre><code>df.loc[:,'L','C2',4:6] 
  </code></pre>
  
  <p>but getting </p>
  
  <blockquote>
    <p>df.loc[:,['L','C2',4:6]]</p>
    
    <p>SyntaxError: invalid syntax</p>
  </blockquote>
  
  <p>with <code>R's dplyr</code></p>
  
  <p>just a one line of code is enough</p>
  
  <pre><code>select(L=0,W=1,C1=2,4:max(ncol(.))
  </code></pre>
  
  <p>why pandas is not straightforward and how can I do this the same thing with pandas ?</p>
  
  <p>the expected output should look like</p>
  
  <pre><code>week                 L                        C2                      4                  5                   6
  1   0.8666370428503979      0.041593443747687364    0.23892433469051455 0.6454746004955415  0.7905993520222332
  2   0.6014424381923764      0.30913305250605294     0.10972378522258008 0.6021133114626169  0.25128495916256977
  3   0.2996812876134075      0.9314494030471506      0.1020881539666203  0.7065238642131539  0.9858423635165023
  4   0.5590790688036144      0.8212812049578435      0.12567153920750518 0.9076131583950552  0.5731702972368342
  5   0.7312243453837555      0.16307047811396225     0.13377623506787528 0.6559325420882364  0.4234963284022535
  </code></pre>