How do you select single or multiple columns from a Pandas DataFrame?

Quick Overview

Asks how to pull one column or several columns out of a pandas DataFrame and what type each approach returns. Tests everyday pandas fluency: bracket and attribute access, loc and iloc, keeping results two-dimensional, and the pitfalls around missing names and copies.

How do you select single or multiple columns from a Pandas DataFrame?

Role: Data Scientist

Category: Data Manipulation (SQL/Python)

Difficulty: easy

Interview Round: Other

How do you select single or multiple columns from a Pandas `DataFrame`? ```hint Check the return type For each way of selecting, ask what kind of object comes back and how many dimensions it has. Also think about column names that cannot be written as a Python attribute. ``` ### What a Strong Answer Covers - Selecting one column and the type that comes back. - Selecting several columns with a list, and how to keep a single column two-dimensional. - Attribute access and the cases where it fails. - Label-based and position-based alternatives, and combining column selection with a row filter. ### Follow-up Questions - How would you select all numeric columns, or all columns whose names start with `sales_`? - You select two columns into a new variable and change a value in it. Does the original DataFrame change? - Why does `df['a', 'b']` raise an error when `df[['a', 'b']]` works?

Overview: Asks how to pull one column or several columns out of a pandas DataFrame and what type each approach returns. Tests everyday pandas fluency: bracket and attribute access, loc and iloc, keeping results two-dimensional, and the pitfalls around missing names and copies.

PracHub logo
General
Nov 25, 2026
easyData ScientistOtherData Manipulation (SQL/Python)
0
0

How do you select single or multiple columns from a Pandas DataFrame?

What a Strong Answer Covers Guidance

  • Selecting one column and the type that comes back.
  • Selecting several columns with a list, and how to keep a single column two-dimensional.
  • Attribute access and the cases where it fails.
  • Label-based and position-based alternatives, and combining column selection with a row filter.

Follow-up Questions Guidance

  • How would you select all numeric columns, or all columns whose names start with sales_ ?
  • You select two columns into a new variable and change a value in it. Does the original DataFrame change?
  • Why does df['a', 'b'] raise an error when df[['a', 'b']] works?