Skip to content
Advertisement

Select rows of a data frame in a loop based on list of indexes

I have one data frame & two (or multiple) lists of indexes:

JavaScript

I want to create a loop where I can select the rows of data. for each iteration, I use one list. so for 1st iteration data has the rows shown in idx1 0,2,4.

how I can do that ?

This is a simplified example, in my actual code, there are different functions that I need to loop on. for each iteration having different rows. Therefore it’s important for me to do that within a loop.

Advertisement

Answer

You can select rows with data.loc[rows].

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement