Pick two columns
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
From the `emp` table, keep only the `name` and `salary` columns, in that order. The result is a DataFrame with every row.
What this exercise teaches
Indexing a DataFrame with a list of labels returns a new DataFrame with those columns in the order you list them. Double brackets are just a list inside the indexing brackets.
A hint if you get stuck
Pass a list of column names inside the square brackets: df[[...]]. Single brackets with one name give a Series.
Try it now, no account needed
This exercise is free. Open it on the practice page, solve it, and get instant feedback with a hint and a worked solution after two tries.
Open this exercise