2015-05-07 39 views
0

您好我有一个像这样的数据框,有超过500行。找到一个空值,并从一个数据帧中删除熊猫

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... 

我想要做的是,我想要在“数据”列中找到空,并从数据框中删除该行。我写了我的代码,但我相信它没有按预期工作,因为行数没有改变。有人可以帮助我吗?

我的代码:

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

这个例子TSV没有任何NaN值在数据列... :( –

+0

下面的两个解决方案也会比使用更多的速度更快。 – Alexander

回答

1

您可以使用布尔面具只保留notnull值:

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

这是'〜'运算符不可读性更强的可读/可读的掩码+1 – EdChum

1

尝试

bigdata_filtered = bigdata_comp_dropped[~bigdata_comp_dropped['data'].isnull()] 
相关问题