using loc to remove nan which appears in 2 or more columns

25 Views Asked by At

I have a basic df as below and i want to remove NaN values when they appear in both Name and Age columns and not just one. the below code i am using removes the 3rd row even though Age = 16 and is not a NaN. ideally i want to use loc method as i have other conditions

thanks

import pandas as pd
import numpy as np

data = [['tom', 10, 'male'], ['nick', 15, 'male'], [np.nan, 16, 'male']]

df = pd.DataFrame(data, columns=['Name', 'Age', 'sex'])
df_new = df.loc[((df['Name'].notnull()) & (df['Age'].notnull()))]
0

There are 0 best solutions below