Certainly! To select multiple columns from a DataFrame in Python using pandas, you can use a list of column names within the selection brackets []. Here's an example:
import pandas as pd
# Sample DataFrame
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'Sex': ['F', 'M', 'M']
}
titanic = pd.DataFrame(data)
# Select the 'Age' and 'Sex' columns
age_sex = titanic[['Age', 'Sex']]
# Display the first 5 rows
print(age_sex.head())
This code will create a DataFrame and then select the 'Age' and 'Sex' columns from it.
