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 learn how to apply a function to a column to create multiple columns.
For this purpose, we are going to define a function that will return multiple values, we will then zip these multiple values and map them into multiple columns in a DataFrame.
Here, we are going to use zip() function, below is the syntax:
zip('object_1','object_2',.....,'object_n')
The zip() function is used to return zipped objects, it contains an iterator, and one by one it passes a value and pairs them.
Also, we are going to map function, which is used to map multiple values, here we will use the map function to call our defined function for getting multiple values the multiple values and the column of DataFrame will be joined together by zip() function.
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