Drop rows of pandas dataframe that don't have finite values in certain variable(s)

心已入冬 提交于 2019-12-08 09:54:58

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!