1 Upvote

Selecting Columns from a Pandas Dataframe Using Loc and iLoc

Python
Data Preprocessing

Source: https://www.analyseup.com/python-data-science-reference/pandas-selecting-dropping-and-renaming-columns.html

#Selects columns between 'Order_No' and 'ProductID'

df.loc[:,'Order_No':'ProductID']

#Select first 5 columns

df.iloc[:,0:5]

By analyseup - Last Updated Jan. 12, 2022, 12:23 a.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Pivoting Pandas Dataframes
Python
Data Preprocessing

Pandas

3
SparkSession instantiate
Python
Data Preprocessing

2
Converting Data Types
Python
Data Preprocessing

Data-cleaning

2
Data Minification
Python
Data Preprocessing

Cleaning

2
Top Contributors
75