Find a null value and drop from a dataframe in Pandas

孤街浪徒 提交于 2020-01-06 19:06:26

问题


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

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?

My code:

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

回答1:


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

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



回答2:


Try

bigdata_filtered = bigdata_comp_dropped[~bigdata_comp_dropped['data'].isnull()]


来源:https://stackoverflow.com/questions/30091012/find-a-null-value-and-drop-from-a-dataframe-in-pandas

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