Python Forum

Full Version: select data based on indice
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have dataframe like this
month value
0 1 12.214394
1 2 -30.114391
2 3 1.343937
3 4 -29.290909
4 5 22.703789
5 6 14.211441
6 7 5.654198
7 8 -28.977440
8 9 8.361656
9 10 12.296993
10 11 18.193127
11 12 -20.491604
12 1 45.214394
13 2 10.885609
14 3 -14.656063
15 4 3.709091
16 5 8.703789
17 6 24.211441
18 7 -46.345802
19 8 4.022560
20 9 8.361656
21 10 -2.703007
22 11 -28.806873
I want to select the values based on the months like this [10,11,12,1,2,3, 10,11,12,1,2,3] and I want to ignore the
the first 123 so the starts from 10,11,12 but the 123 goes into the next year instead of picking from the beginning.

Thanks
Sounds easy, try the following: df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].
Thanks works like a charm
Hi , this copies both the month the values together, is there a way to get only the only values? in the same order as the months?
df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].value.values
or

df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].value.tolist()