Columns are the different fields that contain their particular values when we create a DataFrame. We can perform certain operations on both rows & column values. Here, we are going to perform some operations on a single column. For this purpose, we will use apply() method inside which we will filter our specified column on which we want to apply a function.
The apply() method takes the function which has to be applied on the DataFrame columns. The apply() method traverses each column one by one and then performs the specified operation inside it. To operate on a single column, we will check the column name inside apply() method, and if our column name matches then only the function specified will work.
Syntax:
DataFrame.apply('function','condition')
To work with pandas, we need to import pandas package first, below is the syntax:
import pandas as pd
Let us understand with the help of an example:
Output:
need an explanation for this answer? contact us directly to get an explanation for this answer