Slicing multiple ranges of columns in Pandas, by list of names
<p>I am trying to select multiple columns in a Pandas dataframe in two different approaches:</p>

<p>1)via the columns number, for examples, columns 1-3 and columns 6 onwards.</p>

<p>and </p>

<p>2)via a list of column names, for instance: </p>

<pre><code>years = list(range(2000,2017))
months = list(range(1,13))
years_month = list(["A", "B", "B"])
for y in years:
    for m in months:
        y_m = str(y) + "-" + str(m)
        years_month.append(y_m)     
</code></pre>

<p>Then, <strong>years_month</strong> would produce the following:</p>

<pre><code>['A',
 'B',
 'C',
 '2000-1',
 '2000-2',
 '2000-3',
 '2000-4',
 '2000-5',
 '2000-6',
 '2000-7',
 '2000-8',
 '2000-9',
 '2000-10',
 '2000-11',
 '2000-12',
 '2001-1',
 '2001-2',
 '2001-3',
 '2001-4',
 '2001-5',
 '2001-6',
 '2001-7',
 '2001-8',
 '2001-9',
 '2001-10',
 '2001-11',
 '2001-12']
</code></pre>

<p>That said, what is the best(or correct) way to load only the columns in which the names are in the list <strong>years_month</strong> in the two approaches?</p>