Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
Source by sparkbyexamples.com #
 
PREVIOUS NEXT
Tagged: #select #rows #list #indices #pandas
ADD COMMENT
Topic
Name
9+1 =