select data based on indice - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: select data based on indice (/thread-19778.html) |
select data based on indice - Staph - Jul-14-2019 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 RE: select data based on indice - scidam - Jul-14-2019 Sounds easy, try the following: df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))] .
RE: select data based on indice - Staph - Jul-14-2019 Thanks works like a charm RE: select data based on indice - Staph - Jul-14-2019 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? RE: select data based on indice - scidam - Jul-15-2019 df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].value.valuesor df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].value.tolist() |