Pandas - Filtering None Values

前端 未结 3 1923
旧巷少年郎
旧巷少年郎 2020-12-13 08:39

I\'m using Pandas to explore some datasets. I have this dataframe:

I want to exclude any row that has a city value. So I\'ve tried:

new_df =         


        
相关标签:
3条回答
  • 2020-12-13 08:55

    I hope "where" can do what you expect

    new_df = new_df.where(new_df["city"], None) 
    

    And it is better use np.nan rather than None.

    For more details pandas.DataFrame.where

    0 讨论(0)
  • 2020-12-13 09:07

    Try this to select only the None values for city column:

    new_df = all_df['City'][all_df['City'] == "None"]
    

    Try this to see all other columns which has the same rows of 'City'==None

    new_df = all_df[all_df['City'] == "None"]
    print(new_df.head()) # with function head() you can see the first 5 rows
    
    0 讨论(0)
  • 2020-12-13 09:10

    Consider using isnull() to locate missing values

    all_df[all_df['City'].isnull()]
    
    0 讨论(0)
提交回复
热议问题