For example, I want to keep every 3rd row, but I must keep numbers divisible by 3(or some special rule like that). When I see a number divisible by 3, that restarts the count, meaning I will start counting to 3 from there, unless I see anoter value divisible by 3. Example given below:
import pandas as pd
df = pd.DataFrame.from_dict({'x': [0, 1, 2, 3, 4, 5, 7, 8, 9, 11, 12, 13, 14, 17, 20, 23]})
filtered = pd.DataFrame.from_dict({'x': [0, 3, 7, 9, 12, 17]}) # this is the desired dataframe
print (df, 'nn--------------nn', filtered)
x
0 0
1 1
2 2
3 3
4 4
5 5
6 7
7 8
8 9
9 11
10 12
11 13
12 14
13 17
14 20
15 23
--------------
x
0 0
1 3
2 7
3 9
4 12
5 17