I need to check if a series already exists as a row in the dataframe. The dataframe is as follows-
Name Age University 0 Ankit NaN BHU 1 Aishwarya 21.0 JNU 2 Shaurya 22.0 DU I have tried-
(df == ser).all(1).any() It works fine when the dataframe and series do not have null values. For example, if the series is ['Aishwarya', 21.0, 'JNU'], the output is True, which is correct. However, if the series is ['Ankit', np.nan, 'BHU'], the output is False, even if the series exists in the dataframe.
Minimum, reproducible example for my problem-
details = {'Name':['Ankit', 'Aishwarya', 'Shaurya'], 'Age':[np.nan, 21, 22], 'University':['BHU', 'JNU', 'DU']} df = pd.DataFrame(details, columns = ['Name', 'Age', 'University']) ser1 = pd.Series(['Ankit', np.nan, 'BHU'], index = ['Name', 'Age', 'University']) ser2 = pd.Series(['Aishwarya', 21.0, 'JNU'], index = ['Name', 'Age', 'University']) print((ser1 == df).all(1).any()) print((ser2 == df).all(1).any()) Actual Output-
False True Expected Output-
True True