🎓 A1Learner
🔍
0 of 50 lessons completed

Picking Several Columns

Multi-column selection picks several columns at once. A list of column names inside double brackets returns a smaller DataFrame.

Pick two columns

A list inside double brackets picks product and units.

import pandas as pd

df = pd.DataFrame({
    "product": ["Tea", "Coffee", "Mug"],
    "units": [2, 1, 3],
    "price": [4.50, 6.00, 12.00],
})
print(df[["product", "units"]])

Two brackets keep a table

One column in double brackets is still a DataFrame. The table shape stays.

import pandas as pd

df = pd.DataFrame({
    "product": ["Tea", "Coffee", "Mug"],
    "units": [2, 1, 3],
    "price": [4.50, 6.00, 12.00],
})
print(df[["product"]])

The order follows the list

The list names units first, so units comes first.

import pandas as pd

df = pd.DataFrame({
    "product": ["Tea", "Coffee", "Mug"],
    "units": [2, 1, 3],
    "price": [4.50, 6.00, 12.00],
})
print(df[["units", "product"]])

Example

import io
import pandas as pd

SALES_CSV = """order_id,date,product,category,units,price,region
101,2026-01-05,Tea,Drink,2,4.50,North
102,2026-01-06,Coffee,Drink,1,6.00,South
103,2026-01-07,Mug,Home,3,12.00,East
104,2026-01-08,Notebook,Office,2,8.50,West
105,2026-01-09,Pen,Office,5,2.00,North
106,2026-01-12,Lamp,Home,1,24.00,South
107,2026-01-13,Tea,Drink,4,4.50,East
108,2026-01-14,Coffee,Drink,2,6.00,West
109,2026-01-15,Mug,Home,1,12.00,North
110,2026-01-16,Notebook,Office,3,8.50,South
111,2026-01-19,Pen,Office,2,2.00,East
112,2026-01-20,Lamp,Home,2,24.00,West"""

sales = pd.read_csv(io.StringIO(SALES_CSV))
print(sales[["product", "units", "price"]].head())

Key points

  • Double brackets hold a list of the columns to keep.
  • The result is a DataFrame, not a Series.
  • The picked columns keep the order the list gives them.
  • One bracket with one name gives a Series, and two brackets give a DataFrame.
  • Picking columns is how a wide table is cut down to the columns one job needs.

In this example, the sales table is read from the CSV text. Three columns are picked: product, units, and price. head shows the first five rows of the smaller table.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Python Playground

Exercise

Which code picks the product and price columns as a DataFrame?