Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select specific rows from dataframe in python

select_color = df.loc[df['Color'] == 'Green']
Comment

pandas return specific row

df.iloc[1] # replace index integer with specific row number
Comment

pandas return row

1. 	Selecting data by row numbers (.iloc)
	# myrow = data.iloc[<row selection>]
 	myrow = data.iloc[7]
    myrow = data.iloc[0:9]
    
2. 	Selecting data by label or by a conditional statement (.loc)
	# myrow = data.loc[<row selection.]
  	myrow = data.loc['University ABC']
    
3. 	Selecting in a hybrid approach (.ix) (now Deprecated in Pandas 0.20.1)
	# Works like a .loc but also accepts integers - may lead to unexpected results
Comment

how to select rows with specific values in pandas

#To select rows whose column value is in an iterable array, which we'll define as array, you can use isin:
array = ['yellow', 'green']
df.loc[df['favorite_color'].isin(array)]
Comment

PREVIOUS NEXT
Code Example
Python :: python check if array is subset of another 
Python :: pandas nan to none 
Python :: how to get colored text in python 
Python :: python using datetime as id 
Python :: django migrate not creating tables 
Python :: separate a string in python 
Python :: python if in list multiple 
Python :: what is from_records in DataFrame() pandas in python? 
Python :: python soap 
Python :: filter query objects by date range in Django? 
Python :: how to make a random variable in python 
Python :: pandas add quantile columns 
Python :: % operatior in python print 
Python :: how to convert binary to text in python 
Python :: redis json python 
Python :: Randint Random Library 
Python :: remove element from list 
Python :: time.time() 
Python :: what if we multiply a string in python 
Python :: how to convert into grayscale opencv 
Python :: import get_object_or_404 
Python :: numpy check if an array is all zero 
Python :: Pyspark Aggregation on multiple columns 
Python :: python how to calculate how much time code takes 
Python :: find index of values greater than python 
Python :: how to add window background in pyqt5 
Python :: how to use h5 file in python 
Python :: start python virtual 
Python :: virtual env python 2 
Python :: python split every character in string 
ADD CONTENT
Topic
Content
Source link
Name
8+5 =