Informatics Practices · Class 12 · Python Pandas · Series
PandasSeries⏱️ 5 min read
Dropping Entries
Sometimes you need to throw an item out of a Series. The drop() method removes an entry by its index label and hands you back a new Series without it.
1Drop an entry
Click the ✕ on any row to drop it and watch the Series shrink. The code updates to match what you removed.
Drop entries
Click the ✕ on any row to drop it. drop() returns a NEW Series — the labels you remove simply vanish from the result.
obj2 = obj2.drop('c')
obj2 — click ✕ to drop
a1.50
b12.75
c24.00
d35.25
e46.50
dtype: float64
Nothing dropped yet — the Series still has all 5 entries.
2Dropping a single entry
Pass the label of the entry you want gone. The result is a new Series; the original stays exactly as it was.
drop_one.py
3Dropping several at once
To remove more than one entry, pass a list of labels.
drop_many.py
Note
By default
drop() returns a new Series and leaves the original alone. To change the original itself, pass inplace=True: s.drop('c', inplace=True).Watch Out
The label must actually exist — dropping a label that isn't in the Series raises a
KeyError. Quick Check
s has labels a, b, c, d. What does s.drop(['a', 'c']) return?
Quick Check
How do you make drop() modify the original Series instead of returning a copy?