3

I am looking for an efficient and fast way to select a value: after 5 rows the 6th row value should be saved in variable X, and skip next 5 rows and take value 6th row and save in variable X. Note: Every time remove previous value of x

data=(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17)
piet.t
  • 11,718
  • 21
  • 43
  • 52
Nickel
  • 580
  • 4
  • 19
  • 1
    Possible duplicate of [Pandas every nth row](https://stackoverflow.com/questions/25055712/pandas-every-nth-row) – entropy Mar 20 '19 at 03:51

2 Answers2

2

I think you can using %

s=pd.Series([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17])
s[(np.arange(len(s))+1)%6==0].tolist()
[6, 12]
BENY
  • 317,841
  • 20
  • 164
  • 234
0
import pandas as pd
import numpy as np
data=pd.DataFrame(np.array([1,2,3,4,54,5,6,5,4,35,6,4,3,23,3]))
for i in data.iloc[::6][0]:
    X=i
Minghao
  • 31
  • 4