In this article, we will discuss how to select a single column in a data frame. Now let us try to implement this using Python.
First, let’s create a dataframe
Method 1: Using Dot(dataframe.columnname) returns the complete selected column
Method 2: Using dataframe[columnname] method:
There are some problems that may occur with using dataframe.dot are as follows:
- Through dot method, we cannot Select column names with spaces.
- Ambiguity may occur when we Select column names that have the same name as methods for example max method of dataframe.
- We cannot Select multiple columns using dot method.
- We cannot Set new columns using dot method.
Because of the above reason dataframe[columnname] method is used widely.
Another Example now if we want to select the column Age.
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.