0

I have a dataframe that look like:

df

Out[129]: 
         Unnamed: 0  Region     GeneID  DistanceValue
0                 0     0.0   79677107            0.0
1                 1     0.0   71920480            0.0
2                 2     0.0   77869780            0.0
3                 3     0.0   69838736            0.0
4                 4     0.0  100145371            0.0
            ...     ...        ...            ...
1097355     1097355    42.0       1415            NaN
1097356     1097356    42.0     356855            NaN
1097357     1097357    42.0   74513917            NaN
1097358     1097358    42.0        957            NaN
1097359     1097359    42.0        836            NaN

[1097360 rows x 4 columns]

I want to find all rows with Region value 6 and 8:

I can do so for 6, e.g.:

new_df = df.loc[(df['Region'] == 6)]

I tried sth like

new_df = df.loc[(df['Region'] == 6, 8)]

or

new_df1 = df.loc[(df['Region'] == 6)]

new_df2 = df.loc[(df['Region'] == 8)]

new_df = new_df1 + new_df2

But that doesn't work. Can someone help me with that?

Anja
  • 345
  • 5
  • 21
  • pandas [between](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.between.html) could be helpful. ur data is not good enuf as one cant find values when it's just 0 and 42 in the regions column. [MVCE](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – sammywemmy Apr 06 '20 at 10:18
  • There are a couple of ways. one is `df[df['Region'].isin([6, 8])]` – dimitris_ps Apr 06 '20 at 10:19
  • what doy ou meand with not good enough? – Anja Apr 06 '20 at 10:20
  • 1
    Another way (recommended) `df[ ( df['Region'] == 6 ) | ( df['Region'] == 8 ) ]` so you are selecting the regions with 6 or | region with 8 – dimitris_ps Apr 06 '20 at 10:22

0 Answers0