-1

the dataframe has age column. I want to select only those btw 0 and 100.

usually I do this, first select < 100 then select > 0:

   df_clients = df_clients[df_clients['age'] <100) 
   df_clients = df_clients[df_clients['age']> 0]

The other way is this:

df_clients = df_clients[(df_clients['age'] <100) & (df_clients['age']> 0)]

How to do this with 'and' or '&&' - double && ?

ERJAN
  • 23,696
  • 23
  • 72
  • 146

2 Answers2

1

Try this

df_clients = df_clients[df_clients['age'] < 100][df_clients['age'] > 0]
ksilentstorm
  • 105
  • 9
1

You can use np.logical_and with reduce:

import numpy as np

conditions = [
    df_clients['age'] > 0,
    df_clients['age'] < 100, 
]

mask = np.logical_and.reduce(conditions)

df_clients = df_clients[mask]
Juan Estevez
  • 837
  • 7
  • 13