Ciaren

Select columns

Select columns — selectColumns

Keep only the listed columns (and reorder them).

Use cases

  • Produce a tidy output with just the columns that matter, in a chosen order.
  • Reduce a wide frame to the few columns a downstream step needs.

What it does

Drops every column not listed and reorders the survivors to match your list.

Before
idnameregionamountnotescreated_at
1AliceNorth120.5vip2024-01
2BobSouth89null2024-01
2 rows · 6 cols
Select columns (columns=[amount, region, id])
After
amountregionid
120.5North1
89South2
2 rows · 3 cols

Configuration

Config keyTypeRequiredDescription
columnsstring[]YesColumns to keep, in order

Generated Python code

df_2 = df_1[['region', 'amount']]

Tips & common mistakes

  • Order matters — the output columns follow the order you list them in.
  • To drop just a couple of columns from a wide frame, use Drop columns instead.

See also