Many times while doing data analysis we are dealing with a large data set, having a lot of attributes. All the attributes are not necessarily equally important. As a result, we want to work with only a set of columns in the dataframe. For that purpose, let’s see how we can create views on the Dataframe and select only those columns that we need and leave the rest.
For link to the CSV file used in the code, click here.
Solution #1: A set of columns in the DataFrame can be selected by dropping all those columns which are not needed.
Now we will select all columns except the first three columns.
We can also use the names of the column to be dropped.
Solution #2 : We can individually select all those columns which we need and leave out the rest.
We can also select the columns in a random manner by passing a list to the
Alternatively, we can also name the columns that we want to select.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.