Drop columns you do not need
A pandas exercise from Pandasdrill. Solve it with a Python editor in your browser running real pandas, and it is checked the moment you submit.
The task
Return `emp` without the `emp_id` and `city` columns. Keep every row and the other columns in their original order.
What this exercise teaches
drop(columns=[...]) returns a new DataFrame without those columns and leaves emp itself unchanged. Without columns= (or axis=1) drop searches the index and raises a KeyError, because no row is labeled emp_id.
A hint if you get stuck
drop removes labels. Say that they are column labels with columns=[...], otherwise pandas looks for them among the row labels.
Try it now, free, no account needed
Your first 8 exercises on Pandasdrill are free. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro unlocks every exercise, timed mode and the certificate.
Open this exercise