Selecting Columns from a Pandas Dataframe Using Loc and iLoc

Python

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

 1|  #Selects columns between 'Order_No' and 'ProductID'
 2|  
 3|  df.loc[:,'Order_No':'ProductID']
 4|  
 5|  #Select first 5 columns
 6|  
 7|  df.iloc[:,0:5]
Loc | Iloc
Did you find this snippet useful?

Sign up for free to to add this to your code library