熊猫 - 过滤无值

时间:2017-07-15 10:42:09

标签: python pandas dataframe

我正在使用Pandas来探索一些数据集。我有这个数据框:

enter image description here

我想排除任何具有城市价值的行。所以我试过了:

new_df = all_df[(all_df["City"] == "None") ]
new_df

但后来我得到了一个空数据框:

enter image description here

每当我使用None以外的任何值时,它都有效。知道如何过滤这个数据帧吗?

3 个答案:

答案 0 :(得分:39)

考虑使用isnull()查找缺失值

all_df[all_df['City'].isnull()]

答案 1 :(得分:3)

尝试此操作仅选择city列的None值:

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

尝试此操作以查看具有相同行'City'==None

的所有其他列
new_df = all_df[all_df['City'] == "None"]
print(new_df.head()) # with function head() you can see the first 5 rows

答案 2 :(得分:1)

我希望" UserPasswordCredential userCred = new UserPasswordCredential(userId, userPassword); var authenticationContext = new AuthenticationContext(authString, false); ClientCredential clientCred = new ClientCredential(clientId, clientSecret); AuthenticationResult authenticationResult = await authenticationContext.AcquireTokenAsync(resourceId, clientId, userCred); string token = authenticationResult.AccessToken; "可以做你期望的事情

where

最好使用new_df = new_df.where(new_df["city"], None) 而不是np.nan

有关详细信息pandas.DataFrame.where

相关问题