Skip to content
Learn Netverks

Lesson

Step 8/36 22% through track

columns-selection

Column selection

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~2 min
Level
beginner

This lesson

This lesson teaches Column selection: Pandas tabular manipulation—indexing, dtypes, reshaping, and analysis habits for real-world tables.

Teams apply Column selection in every serious Pandas project—skipping it leaves blind spots in analysis and reviews.

You will apply Column selection in contexts like: CSV/Parquet analysis, ETL notebooks, and ad hoc reporting.

Read the narrative, run `import pandas as pd` snippets with in-memory DataFrames (install pandas and numpy with pip if needed), inspect `.head()`, `.dtypes`, and complete MCQs.

When you can explain the previous lesson's ideas in your own words.

Select columns with bracket notation. One column returns a Series; a list of columns returns a DataFrame. Use df.filter or df.loc for advanced patterns.

Basic selection

import pandas as pd
df = pd.DataFrame({'a': [1,2], 'b': [3,4], 'c': [5,6]})
s = df['a']          # Series
sub = df[['a', 'c']] # DataFrame
print(type(s), type(sub))

Adding and renaming

  • df['new_col'] = values — add or overwrite column
  • df.rename(columns={'old': 'new'}) — rename (returns copy by default)
  • df.drop(columns=['x']) — remove columns
  • df.assign(total=lambda d: d['a'] + d['b']) — functional style

Pitfalls

Chained assignment (df[mask]['col'] = val) can fail silently—prefer df.loc[mask, 'col'] = val. Dot notation (df.col) only works for valid Python identifiers.

Important interview questions and answers

  1. Q: df['a'] vs df[['a']]?
    A: Single brackets → Series; double brackets → DataFrame with one column.
  2. Q: Chained assignment?
    A: Setting on a slice may not modify original—use loc with row and column together.

Self-check

  1. Select two columns into a new DataFrame.
  2. How do you add a computed column?

Pitfall: Chained assignment df[mask]['col']=x triggers SettingWithCopyWarning—use loc.

Interview prep

Single vs double brackets?

df['a'] → Series; df[['a']] → DataFrame.

assign?

Functional column add returning new DataFrame—supports method chaining.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • bracket vs dot?
  • Select multiple cols?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump