To add a new column in the DataFrame, we will create a list as a column and then, the list can be assigned to the DataFrame.
List as a column:
list_name = [values]
Adding to the DataFrame:
dataframe['column_name'] = list_name
To work with MultiIndex in Python Pandas, we need to import the pandas library. Below is the syntax,
import pandas as pd
Example:
Output:
Data before adding column... Name Age 0 Alvin 21 1 Alex 22 2 Peter 19 Data after adding column... Name Age Course 0 Alvin 21 B.Tech 1 Alex 22 MCA 2 Peter 19 B.Eneed an explanation for this answer? contact us directly to get an explanation for this answer