Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select multiple columns in pandas dataframe

df1 = df[['a', 'b']]
Comment

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 ;)
Comment

select multi columns pandas

df1 = df[['a', 'b']]
Comment

PREVIOUS NEXT
Code Example
Python :: list dataframe to numpy array 
Python :: numpy datatime object 
Python :: create payment request in stripe 
Python :: create dictionary without removing duplicates from dataframe 
Python :: plotly change legend name 
Python :: how to get the length of a string in python stack overflow 
Python :: run python file from cmd 
Python :: import os in python 
Python :: string comparison in python 
Python :: create new spreadsheet 
Python :: write hexadecimal in python 
Python :: python list copy 
Python :: argparse one argument or without argument 
Python :: função map python 
Python :: service 
Python :: how to create list in python 
Python :: python pandas sum of series 
Python :: how to read an xml file 
Python :: type() in python 
Python :: python size of list 
Python :: python 3.8 vs 3.10 
Python :: python cast to int 
Python :: django drf 
Python :: min and max in python 
Python :: Python - How To Pad String With Spaces 
Python :: convert string input into a nested tuple in python 
Python :: django snippet 800 
Python :: python random number between x and y 
Python :: python import local file 
Python :: Define the learnable resizer utilities 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =