Search code examples
pythonpandasnumpyjupyter-notebookcell

Kernel dies after using np.logical_and


So I have created a sample dataset that is as follows:

import numpy as np
import pandas as pd

x = range(1, 10)
arr1 = [1, 2, 3, 4, 5, 6, 7, 8, 9]
arr2 = np.random.randint(x)
arr3 = np.random.randint(x)
arr4 = np.random.randint(x)


dict_df = {
    'arr1' : arr1,
    'arr2' : arr2,
    'arr3' : arr3,
    'arr4' : arr4
}


df = pd.DataFrame(dict_df)

When printed this works fine, though when I try to add:

filt = np.logical_and(df['arr1']==0, df['arr2']==0, df['arr3']==0) 

the kernel dies, (at the top of the screen it says Dead Kernel) Any ideas? Thanks!


Solution

  • np.logical_and takes only 2 parameters. Try this instead

    filt = (df['arr1']==0) & (df['arr2']==0) & (df['arr3']==0)
    print(filt)
    
    0    False
    1    False
    2    False
    3    False
    4    False
    5    False
    6    False
    7    False
    8    False
    dtype: bool