How to create list of 3 or 4 columns of Dataframe in Pandas when we have 20 to 50 colums?
<p>When we create list using the below code, we get the list of all the columns but I want to get the list of only 3 to 5 specific columns.</p>

<p>col_list= list(df)</p>

<p>Use slicing of <code>list</code>:</p>

<pre><code>df[df.columns[2:5]]
</code></pre>

<p>Sample:</p>

<pre><code>df = pd.DataFrame({'A':[1,2,3],
                   'B':[4,5,6],
                   'C':[7,8,9],
                   'D':[1,3,5],
                   'E':[5,3,6],
                   'F':[7,4,3]})

print (df)
   A  B  C  D  E  F
0  1  4  7  1  5  7
1  2  5  8  3  3  4
2  3  6  9  5  6  3

print (df.columns[2:5])
Index(['C', 'D', 'E'], dtype='object')

print (df[df.columns[2:5]])
   C  D  E
0  7  1  5
1  8  3  3
2  9  5  6
</code></pre>

<p>Another solution:</p>

<pre><code>col_list= list(df)
print (col_list[2:5])
['C', 'D', 'E']

print (df[col_list[2:5]])
   C  D  E
0  7  1  5
1  8  3  3
2  9  5  6
</code></pre>

python pandas data-science