How To Remove Columns Of A DataFrame?
Table Of Contents:
- Syntax For Removing Columns Of Data Frame.
- Examples Of Column Removal.
(1) Syntax:
DataFrame.pop(item)
Description:
- Return the item and drop it from the frame. Raise KeyError if not found.
Parameters:
- item: label – Label of column to be popped.
Returns:
- Series – The Dropped Column
(2) Examples Of pop() Method:
Example-1
import pandas as pd
student = {'Name':['Subrat','Abhispa','Arpita','Anuradha','Namita'],
'Roll_No':[100,101,102,103,104],
'Subject':['Math','English','Science','History','Commerce'],
'Mark':[95,88,76,73,93]}
student_object = pd.DataFrame(student)
student_object
Output:
dropped = student_object.pop('Mark')
dropped
Output:
0 95
1 88
2 76
3 73
4 93
Name: Mark, dtype: int64
Note:
- The ‘pop()’ method has returned the, removed column values as a series.
student_object
Output:
Note:
- Here you can see that the ‘Mark’ column has been dropped.