# SignatureDataFrame.pop(column_name)
It takes a single parameter, column_name
, which represents the name of the column to be removed from the DataFrame.
It returns the removed column as a
If the column with the specified name does not exist, it raisesKeyError
.
import pandas as pd# including pandas packagedf= pd.read_csv("data.csv")# popping Medical Expenses# from above loaded datasetpopped_column = df.pop("Medical Expenses")# printing on screenprint(popped_column)
Line 3: We use read_csv
from Pandas package to load the data.csv
dataset.
Line 6: We invoke DataFrame.pop("Medical Expenses")
to get the Medical Expenses
column from data.csv
file. It returns column values as Pandas series.
Line 8: We print the removed column stored in the popped_column
variable as Pandas series.