In Pandas, we can achieve this task by using DataFrame.apply() method.
Pandas.DataFrame.apply() Method
This function itself takes a function as a parameter which has to be applied on the columns. To apply the function to multiple columns, we just need to define the name of the columns inside pandas.DataFrame.apply() method.
Syntax:
DataFrame.apply(parameters)
Parameter(s):
- It takes the function which has to be applied on the column values.
- It takes several other optional parameters like axis, raw, result_type, **kwds.
To work with Python Pandas, we need to import the pandas library. 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