Issue
I have to find the row number from the dataframe where there is null values in specific columns. Which pandas function shall I use?
Solution
Considering the dataframe below :
import pandas as pd
import numpy as np
data_dict = {'col1': [np.nan, 'bar', 'baz','missing'],
'col2': ['', 'foo', np.nan, 'bar'],
'col3': [249,np.nan,924,np.nan]
}
df = pd.DataFrame (data_dict)
print(df)
col1 col2 col3
0 NaN 249.0
1 bar foo NaN
2 baz NaN 924.0
3 missing bar NaN
You can use the pandas.isnull
to get your expected output :
out = df.loc[df[['col1','col2']].isnull().any(1)].index.tolist()
print(out)
[0, 2]
Answered By - M92_
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.