Pandas Pop β pd.Dataframe.Pop()
Remove column in pandas dataframe
Pandas Pop is the sound a column makes when itβs removed from a datasetβ¦pop!
Popping a column in pandas is no different. We use pd.DataFrame.pop when we want to remove a column.
What is Pandas Pop?
Pop will is the pandas function to:
- Remove your column from a dataframe
- Return that column youβre dropping as a series so you can use it (if you want)
df.pop() is very similar to df.drop(), but .drop() will return the DataFrame with the column removed. Whereas .pop() will return the column.
I use pop when Iβm creating a dummy column. A column that will only temporarily be used and I donβt want my dataframe to become sloppy.
If you need to remove multiple columns from your dataset, you can either .pop() multiple times, or use pandas .drop() instead. With .drop() you can pass a list of columns (or rows) and theyβll be dropped from your DataFrame.
Pop doesnβt take any extra arguments so you donβt need to worry about changing anything. Did you know that pop is also used with regular vanilla python? Check out python pop.
Make sure to make a βpoppingβ sound whenever you call df.pop()