In this article, you’ll learn the different methods to extract a single column and how each affects the result.
# Create sample DataFrame
import pandas as pd
df = pd.DataFrame({
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'Los Angeles', 'Chicago']
})
Method 1: Using Bracket Notation (Recommended)
This is the most common and robust method to select a single column:
# Select single column 'Name'
name_column = df['Name']
print(name_column)
This returns a Pandas Series, not a DataFrame.
0 Alice
1 Bob
2 Charlie
Name: Name, dtype: object
Note: This method works even if column names have spaces or special characters.