
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python - Select multiple columns from a Pandas dataframe
Let’s say the following are the contents of our CSV file opened in Microsoft Excel −
At first, load data from a CSV file into a Pandas DataFrame −
dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv")
To select multiple column records, use the square brackets. Mention the columns in the brackets and fetch multiple columns from the entire dataset −
dataFrame[['Reg_Price','Units']]
Example
Following is the code −
import pandas as pd # Load data from a CSV file into a Pandas DataFrame: dataFrame = pd.read_csv("C:\Users\amit_\Desktop\SalesData.csv") print("\nReading the CSV file...\n",dataFrame) # displaying two columns res = dataFrame[['Reg_Price','Units']]; print("\nDisplaying two columns : \n",res)
Output
This will produce the following output −
Reading the CSV file... Car Reg_Price Units 0 BMW 2500 100 1 Lexus 3500 80 2 Audi 2500 120 3 Jaguar 2000 70 4 Mustang 2500 110 Displaying two columns : Reg_Price Units 0 2500 100 1 3500 80 2 2500 120 3 2000 70 4 2500 110
- Related Articles
- Select multiple columns in a Pandas DataFrame
- Python Pandas - How to select multiple rows from a DataFrame
- Python Pandas - Plot multiple data columns in a DataFrame?
- Python - How to select a column from a Pandas DataFrame
- Python Pandas - Select a subset of rows from a dataframe
- How to sort multiple columns of a Pandas DataFrame?
- Plot multiple columns of Pandas DataFrame using Seaborn
- Python Pandas – Find unique values from multiple columns
- Python - Grouping columns in Pandas Dataframe
- How to select all columns except one in a Pandas DataFrame?
- Python Pandas - Query the columns of a DataFrame
- Python - Name columns explicitly in a Pandas DataFrame
- Python Pandas - Filtering columns from a DataFrame on the basis of sum
- Python Pandas - How to select rows from a DataFrame by integer location
- How to select multiple DataFrame columns using regexp and datatypes

Advertisements