pylearner
pylearner

Reputation: 1460

Finding out the missing value in dataframe based on a column

Is there a solution to find out the missing values based on column

for example :

Field_name                Field_Type     Field_Id
Message type identifier       M              0
Nan                           M              1
Bitmap secondary              C              1
Nan                           C              2
Processing code               M              3
Nan                           M              4
Amount-Settlement             C              5

So here I want to know the missing values in the column Field_name and the Field_Type = 'M', Ignoring the missing values in Field_Type = 'C'

Expected Output :

Field_name   Field_Type  Field_Id
Nan                M    1
Nan                M    4

Edit : Can we do this for a list of dataframes ?

data_list = [df1,df2,df3]


output : result [[missngvalues in df1],[missngvalues in df2],[missngvalues in df3]]

Upvotes: 7

Views: 338

Answers (1)

jezrael
jezrael

Reputation: 863741

If nan are missing values chain mask Series.isna and Series.eq for == by & for botwise AND:

df[df.Field_name.isna() & df.Field_Type.eq('M')]

If nan are strings compare both by Series.eq:

df[df.Field_name.eq('Nan') & df.Field_Type.eq('M')]

print (df)

  Field_name Field_Type  Field_Id
1        Nan          M         1
5        Nan          M         4

EDIT:

If working with list of DataFrames:

data_list = [df1,df2,df3]
result = [df[df.Field_name.isna() & df.Field_Type.eq('M')] for df in data_list]

Upvotes: 2

Related Questions