Skip to main contentSkip to solution

TexasCalifornia
14445
25534
32367
46733

For the DataFrame (df) given above, which of the following are correct ways to access column 'Texas'?

A. df['Texas']

B. df('Texas')

C. df.Texas

D. df.['Texas']

Solution

✅ Correct Option: 2

df['Texas'] uses square-bracket indexing with the column label, which is the standard way to select a column and returns it as a Series.

df.Texas uses attribute-style access. It works because the column name is a valid Python identifier and does not clash with an existing DataFrame attribute or method.

So A and C are correct.


B: df('Texas') uses round brackets, which would try to call the DataFrame as a function. A DataFrame is not callable, so this raises a TypeError.

D: df.['Texas'] is a syntax error, because a dot cannot be placed directly before square brackets.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question