删除具有非缺失值的行

时间:2018-12-31 22:42:29

标签: python pandas dataframe

我有一个很大的数据框,其中有一列用Nan和整数填充。 我确定了不为空的行(即为notnull()返回False):

df.loc[df.score.notnull()]

如何删除这些行并保留缺少值的行?

此代码无效:

df.drop(df.score.notnull()]

2 个答案:

答案 0 :(得分:0)

您可以使用df.loc[df.score.isnull()]df.loc[~df.score.notnull()]

答案 1 :(得分:0)

假设您想要使用相同的数据框,则可以使用:

    <SampBoxLayout>:
orientation: "vertical"
padding: 10
spacing: 10


BoxLayout:
    orientation: "vertical"
    height: 30

    BoxLayout:
        orientation: "vertical"
        size_hint_x: .25
        size_hint_y: .25

        TabbedPanel:
            do_default_tab: False
            size: 5, 5

            TabbedPanelItem:
                text: "Home"
                Label:
                    text: "Content of Home"
            TabbedPanelItem:
                text: "Browse"
                Label:
                    text: "Content of Browse"
            TabbedPanelItem:
                text: "Radio"
                Label:
                    text: "Content of Radio"
            TabbedPanelItem:
                text: "Made for You"
                Label:
                    text: "Content of Made For You"
            TabbedPanelItem:
                text: "Recently Played"
                Label:
                    text: "Content of Recently Played"
            TabbedPanelItem:
                text: "Favorite Songs"
                Label:
                    text: "Content of Recent Songs"
            TabbedPanelItem:
                text: "Albums"
                Label:
                    text: "Content of Albums"
            TabbedPanelItem:
                text: "Artists"
                Label:
                    text: "Content of Artists"
            TabbedPanelItem:
                text: "Stations"
                Label:
                    text: "Content of Stations"
            TabbedPanelItem:
                text: "Local Files"
                Label:
                    text: "Content of Local Files"
            TabbedPanelItem:
                text: "Videos"
                Label:
                    text: "Content of Videos"
            TabbedPanelItem:
                text: "Videos"
                Label:
                    text: "Content of Videos"
            TabbedPanelItem:
                text: "Podcasts"
                Label:
                    text: "Content of Podc