Python Forum
select data based on indice
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
select data based on indice
#1
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
Reply
#2
Sounds easy, try the following: df[(df.index > 4) & (df.month.isin([10, 11, 12, 1, 2, 3]))].
Reply
#3
Thanks works like a charm
Reply
#4
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?
Reply
#5
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()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Supervised learning, tree based model - problems splitting data Pixel 0 644 May-16-2023, 05:25 PM
Last Post: Pixel
  Grouping Data based on 30% bracket purnima1 0 940 Feb-16-2023, 07:14 PM
Last Post: purnima1
  Make unique id in vectorized way based on text data column with similarity scoring ill8 0 861 Dec-12-2022, 03:22 AM
Last Post: ill8
  Pandas Data frame column condition check based on length of the value aditi06 1 2,655 Jul-28-2021, 11:08 AM
Last Post: jefsummers
  Dropping Rows From A Data Frame Based On A Variable JoeDainton123 1 2,186 Aug-03-2020, 02:05 AM
Last Post: scidam
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 4,244 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  Select column between to dates CSV data PythonJD 0 1,761 Apr-14-2020, 12:22 PM
Last Post: PythonJD
  Select data from between two timestamps Makada 18 23,906 Feb-07-2020, 09:56 AM
Last Post: Makada
  Sample based on the distribution of a feature to create more balanced data set dervast 1 1,734 Nov-15-2019, 12:25 AM
Last Post: schuler
  Grouping data based on rolling conditions kapilan15 0 1,930 Jun-05-2019, 01:07 PM
Last Post: kapilan15

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020