I have a data frame, all of the values of some rows are nan (such as rows 0, 2) in the following. Some rows have value and nan. I want to find the index of the rows which they have value, value nan. (i.e I want to exclude those rows which their all values are nan). For example, in the following data frame, I want index = [1, 3,4, 5].
import pandas as pd
df1 = pd.DataFrame()
df1['val1'] = [np.nan, 100, np.nan, 30, 40, 1]
df1['val2'] = [np.nan, 30, np.nan, np.nan, -40,2]
df1['val3'] = [np.nan, 10, np.nan, 300, np.nan, 3]
CodePudding user response:
Try with notna
with any
out = df1.index[df1.notna().any(1)].tolist()
Out[341]: [1, 3, 4, 5]