0

I have dataframe cannot show the whole data(confidential) which have a longitudes & latitudes points all around the world but I need to filter for just one country

suppose this is data

enter image description here

Now I have to filter rows data for a specific country which have co-ordinates ranges this

`latitude` :  8°4′ N to 37°6′ N
`longitude` : 68°7′ E to 97°25′ E

so I tried this

df_filtered = df[38 > df['LATITUDE'] > 8 and 98 > df['LATITUDE'] > 68]  

but this is giving this weird error

ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().

Saurabh
  • 1,592
  • 2
  • 14
  • 30
  • df[df.a.between(8,38) & df.a.between(68,98)] – BENY Aug 02 '19 at 19:03
  • While this is correct @WeNYoBen since OP is asking for it, the `|` operator would make more sense – Erfan Aug 02 '19 at 19:06
  • No worries guys,thanks for sharing the duplicate post link `df_filtered = df.loc[(df['LATITUDE'] >=8) & (df['LATITUDE'] <=38) & (df['LONGITUDE'] >=68) & (df['LONGITUDE'] <=98)]` this worked – Saurabh Aug 02 '19 at 19:14
  • @Saurabh your logic does not make sense: `df_filtered = df.loc[((df['LATITUDE'] >=8) & (df['LATITUDE'] <=38)) | ((df['LONGITUDE'] >=68) & (df['LONGITUDE'] <=98))` This makes more sense – Erfan Aug 02 '19 at 19:27

1 Answers1

1

use between

df_filtered = df[(df['LATITUDE'].between(8,38) ) &  (df['LONGITUDE'].between(68,98))]  
Zaynul Abadin Tuhin
  • 31,407
  • 5
  • 33
  • 63