Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

select rows from a list of indices pandas

#Below are quick examples.
# How to select Pandas Rows Based on list using df.iloc[ind_list]
ind_list = [1, 3]
df.iloc[ind_list]

# How to select Pandas Rows Based on list using df.loc[df.index[index_list]]
index_list = [0,2]
df.loc[df.index[index_list]]

# Get Pandas rows on list index using index.isin().
df2=df[df.index.isin([1,3])]
print(df2)

# Get pandas rows on list index by df.time().
df2=df.take([1,2])
print(df2)

# Get Pandas rows on list index by df.query()
index_list = [1,2]
df2=df.query('index in @index_list')
print(df2)
Comment

PREVIOUS NEXT
Code Example
Python :: how to create a matrix using python 
Python :: convert list to nd array 
Python :: how to use if else in lambda python 
Python :: python parcourir un dictionnaire 
Python :: tqdm enumerate 
Python :: search dictionary for value 
Python :: print 1to 10 number without using loop in python 
Python :: python function returns function 
Python :: python date to timestamp 
Python :: how to open a website using python 
Python :: pandas filter with given value 
Python :: root mean squared error 
Python :: remove first 3 columns pandas 
Python :: installation of uvicorn with only pure python dependencies 
Python :: tkinter how to remove button boder 
Python :: how to remove tkinter icon 
Python :: pandas group by day 
Python :: python from float to decimal 
Python :: python web parse 
Python :: how to find the data type in python 
Python :: python overwrite line print 
Python :: count elements in list 
Python :: python find directory of file 
Python :: np.percentile 
Python :: flask client ip 
Python :: cut rows dataframe 
Python :: tabula python 
Python :: python stop while loop after time 
Python :: create app in django 
Python :: requests.Session() proxies 
ADD CONTENT
Topic
Content
Source link
Name
4+3 =