本文介绍了查找空值并从Pandas的数据框中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的数据框,包含500多个行.

Hi I have a dataframe like this with 500+ rows.

    company_url company tag_line    product data
0   https://angel.co/billguard  BillGuard   The fastest smartest way to track your spendin...   BillGuard is a personal finance security app t...   New York City · Financial Services · Security ...
1   https://angel.co/tradesparq Tradesparq  The world's largest social network for global ...   Tradesparq is Alibaba.com meets LinkedIn. Trad...   Shanghai · B2B · Marketplaces · Big Data · Soc...
2   https://angel.co/sidewalk   Sidewalk    Hoovers (D&B) for the social era    Sidewalk helps companies close more sales to s...   New York City · Lead Generation · Big Data · S...
3   https://angel.co/pangia Pangia  The Internet of Things Platform: Big data mana...   We collect and manage data from sensors embedd...   San Francisco · SaaS · Clean Technology · Big ...
4   https://angel.co/thinknum   Thinknum    Financial Data Analysis Thinknum is a powerful web platform to value c...   New York City · Enterprise Software · Financia...

我想做的是我想在数据"列中找到null并从数据框中删除该行.我为此编写了代码,但由于行数没有变化,因此我认为它无法按预期工作.有人可以帮我吗?

What I want to do is that I want to find null in the "data" column and drop the row from the dataframe. I wrote my code for it but I believe it didn't work as expected since the number of rows didn't change. Could someone help me on this?

我的代码:

for item in bigdata_comp_dropped.iterrows():
    if item[1][4] == "":
        bigdata_comp_dropped.drop(item[1])

推荐答案

您只能保留 notnull 值,使用布尔掩码:

You can keep only the notnull values using a boolean mask:

df = df[df["data"].notnull()]

这篇关于查找空值并从Pandas的数据框中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 19:32