Instagram
youtube
Facebook
Twitter

Select Multiple Columns of a Pandas DataFrame

Select Multiple Columns of a Pandas DataFrame
     
Short Description of the Program:

This program reads data from a CSV file and selects multiple columns (e.g., "Name" and "City") from the       DataFrame.
     
Explanation:

  • df[['Name', 'City']]
    Use a list of column names inside double square brackets to select multiple columns.

     
  • This returns a new DataFrame containing only the specified columns.
     

Program:

import pandas as pd

df = pd.read_csv('data.csv')

selected_columns = df[['Name', 'City']]

print(selected_columns)