Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas select row by index

#for single row
df.loc[ index , : ]

# for multiple rows
indices = [1, 20, 33, 47, 52 ]
new_df= df.iloc[indices, :]
Comment

how to get a row from a dataframe in python

df.iloc[[index]]
Comment

pandas select a row

#select the first row 
df.iloc[1]
#select the first row and return the value in column ['Biologie']
candidate_df.iloc[1]['Biologie']
Comment

select rows from dataframe pandas

from pandas import DataFrame

boxes = {'Color': ['Green','Green','Green','Blue','Blue','Red','Red','Red'],
         'Shape': ['Rectangle','Rectangle','Square','Rectangle','Square','Square','Square','Rectangle'],
         'Price': [10,15,5,5,10,15,15,5]
        }

df = DataFrame(boxes, columns= ['Color','Shape','Price'])

select_color = df.loc[df['Color'] == 'Green']
print (select_color)
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

PREVIOUS NEXT
Code Example
Python :: generate a random letter using python 
Python :: python vs c++ 
Python :: append many items to list python 
Python :: django models.py convert DateTimeField to DateField 
Python :: self-xss meaning 
Python :: dropout keras 
Python :: python add to file 
Python :: biggest of 3 numbers in python 
Python :: change the frequency to column in pandas 
Python :: script python to download videio from any website 
Python :: /bin/sh: 1: python: not found 
Python :: python numpy array change axis 
Python :: how to import sin and cos in python 
Python :: python list divide 
Python :: python find the average of a list 
Python :: python-telegram-bot 
Python :: python function returns function 
Python :: mss python install 
Python :: user input python 
Python :: print current line number python 
Python :: how to get the local time in python 
Python :: how to sort list of dictionaries in python 
Python :: python dictionary rename key 
Python :: how to make an infinite loop python 
Python :: python send image server 
Python :: dict typing python 
Python :: socket io python 
Python :: python read integer from stdin 
Python :: python grid 
Python :: flask subdomains 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =