How to select multiple columns?

QuestionsQuestions4 SkillsProPandas Selecting DataNov, 02 2025
0102

To select multiple columns from a DataFrame in Python, you can use a list of column names within the selection brackets []. Here's an example using a DataFrame named titanic:

# Select the 'Age' and 'Sex' columns
age_sex = titanic[["Age", "Sex"]]

# Display the first 5 rows
print(age_sex.head())

This will give you a new DataFrame containing only the specified columns.

0 Comments

no data
Be the first to share your comment!