Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select 2 cols from dataframe python pandas

# Convert the dictionary into DataFrame 
df = pd.DataFrame(data)
  
# select two columns
df[['Name', 'Qualification']]
Comment

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

PREVIOUS NEXT
Code Example
Python :: python recursive sum of digit 
Python :: how to save a pickle file 
Python :: python Program for Sum of the digits of a given number 
Python :: Reverse an string Using Recursion in Python 
Python :: example of django template for forms 
Python :: check input in python 
Python :: tkinter button position 
Python :: flask sqlalchemy query specific columns 
Python :: create exe from python script 
Python :: python check if all caps 
Python :: keys in python 
Python :: python ternary 
Python :: python merge two lists alternating 
Python :: change python3 as default for mac 
Python :: if list of columns exist pandas 
Python :: python assert 
Python :: python depth first search 
Python :: list directory in python 
Python :: how to iterate over object in python 
Python :: find index of maximum value in list python 
Python :: sort a stack using recursion 
Python :: python test if string begins with python 
Python :: python webbrowser close tab 
Python :: square all elements in list python 
Python :: create an array of n same value python 
Python :: terms for list of substring present in another list python 
Python :: discord bot python delete messages like mee6 
Python :: python iterate through files 
Python :: python how to get pixel values from image 
Python :: list files python 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =