问题
I cannot see what the built-in function is for the following simple but seemingly common/useful task: Drop rows which have no value for any of my key columns.
def keepIfPopulated(adf,interestingVars):
good=0
for vv in interestingVars:
good+=adf[vv].notnull()
return(adf[good>0])
If there was just one column of interest, I could choose to keep it, but most pandas functions take one or more labels as arguments, so this question is about how to check on one or more columns at once.
回答1:
adf = adf.dropna(subset=interestingVars, how='all')
来源:https://stackoverflow.com/questions/15626215/drop-rows-of-pandas-dataframe-that-dont-have-finite-values-in-certain-variable