With pandas version >= 0.20.0 you can:
df = df[df.index.notnull()]
With older versions:
df = df[pandas.notnull(df.index)]
To break it down:
notnull
generates a boolean mask, e.g. [False, False, True]
, where True denotes the value at the corresponding position is null (numpy.nan
or None
). We then select the rows whose index corresponds to a true value in the mask by using df[boolean_mask]
.