Home > Back-end >  Python : How can i iterate 3 row values from dataframe at a single time? And then again next 3 value
Python : How can i iterate 3 row values from dataframe at a single time? And then again next 3 value

Time:12-03

I have a data frame -

Name  Rank
A     2
B     3
C     6
D     7
E     4
F     3
G     9
H     2
I     5

I want Rank Column 3 values at a time. such as -

2
3
6

and Next again I want to Rank Column 3 values at a time. such as -

3
6
7

and Next again I want to Rank Column 3 values at a time. such as -

6
7
4

Like in this format, you can use any way loop or any other way. I don't know how I can do this, please help me to find out the solution.

CodePudding user response:

Let us do

[df.Rank.tolist()[x:x 3] for x in df.index[0:-2]]
[[2, 3, 6], [3, 6, 7], [6, 7, 4], [7, 4, 3], [4, 3, 9], [3, 9, 2], [9, 2, 5]]
  • Related