Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas select multiple columns

#Example, in a df with about 20 columns
#If you want to select columns 1-3, 7, 8, 12-15
# Use numpy's np.r_ to slice the columns and parse it into pandas iloc[] slicer

df.iloc[:, np.r_[1:3, 7, 8, 12:15]]
#This selects all rows "df.iloc[:," and then these selected columns "np.r_[1:3, 7, 8, 12:15]]"
#Remember to import numpy ;)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #select #multiple #columns
ADD COMMENT
Topic
Name
2+2 =