40 Algorithms Every Programmer Should Know
上QQ阅读APP看书,第一时间看更新

Column selection

In machine learning algorithms, selecting the right set of features is an important task. Out of all of the features that we may have, not all of them may be needed at a particular stage of the algorithm. In Python, feature selection is achieved by column selection, which is explained in this section. 

A column may be retrieved by name, as in the following:

>>> df[['name','age']]
     name  age
0   Fares   32
1   Elena   23
2  Steven   40

The positioning of a column is deterministic in a DataFrame. A column can be retrieved by its position as follows:

>>> df.iloc[:,3] 
0 True
1 False
2 True

Note that, in this code, we are retrieving the first three rows of the DataFrame.