I have following data & i want to find only Id where rest of all column has null values with the help of pandas, How can i take only Id which has all column is null.
CodePudding user response:
Use if Id
is column use DataFrame.isna
with remove Id
column and test if all values are True
s by DataFrame.all
, last filter by boolean indexing
with DataFrame.loc
:
id1 = df.loc[df.drop('Id', axis=1).isna().all(axis=1), 'Id'].tolist()
#if need omit first column for test
id1 = df.loc[df.iloc[:, 1:].isna().all(axis=1), 'Id'].tolist()
If Id
is index
use:
id1 = df1.index[df1.isna().all(axis=1)].tolist()