2015-05-07 37 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()] 
相關問題