I am trying to look up rows containing non-Null values of a specific item. Both Item_Weight (float) and Item_Identifier (str) come from different columns of the dataframe.
Here's the code to generate the DF:
import numpy as np
import pandas as pd
df = pd.DataFrame()
np.random.seed(seed=6)
df['col0']=np.random.randn(100)
lett=['a','b','c','d']
df['col1']=np.random.choice(lett,100)
toz = np.random.randint(0,100,15)
#Randomly set some values of col0 to null.
df.loc[toz,'col0']=np.NaN
df.loc[df.loc[df['col0'].isnull()==False] & df.loc[df['col1']=='b']]
Throws TypeError:
TypeError: ufunc 'bitwise_and' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
df.loc[(df['col0'].isnull() == False) & (df.loc[df['col1'] == 'b'])]
Throws ValueError:
ValueError: operands could not be broadcast together with shapes (56,) (2,)
Instead if I query like:
df.loc[(df['col0'].isnull() == False) & (df.loc[df['col1'] == 'b'])]
I get another TypeError:
TypeError: Could not operate False with block values unsupported operand type(s) for &: 'bool' and 'float'
I am able to query each part separately (col0 == Null or col1 == 'b'). But I cannot use the & operation on them. Is there a workaround? What am I doing wrong?