欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

DataFrame如何找出有空值的行

 更新時間:2024年02月02日 10:31:09   作者:大地之燈  
這篇文章主要介紹了DataFrame如何找出有空值的行問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教

DataFrame找出有空值的行

import pandas as pdimport numpy as np
n = np.arange(20, dtype=float).reshape(5,4)
n[2,3] = np.nan
index = ['index1', 'index2', 'index3', 'index4', 'index5']
columns = ['column1', 'column2', 'column3', 'column4']
frame3 = pd.DataFrame(data=n, index=index, columns=columns)
frame3
column1column2column3column4
index10.01.02.03.0
index24.05.06.07.0
index38.09.010.0NaN
index412.013.014.015.0
index516.017.018.019.0
frame3.isnull()
column1column2column3column4
index1FalseFalseFalseFalse
index2FalseFalseFalseFalse
index3FalseFalseFalseTrue
index4FalseFalseFalseFalse
index5FalseFalseFalseFalse
# any() 作用:返回是否至少一個元素為真
# 直接求any(),得到的每一列求any()計算的結果
frame3.isnull().any()
column1    False
column2    False
column3    False
column4     True
dtype: bool

判斷有空值的行

# 方法一:設置any的axis參數(shù)
frame3.isnull().any(axis = 1)
index1    False
index2    False
index3     True
index4    False
index5    False
dtype: bool
# 方法二:先轉置再any
frame3.isnull().T.any()
index1    False
index2    False
index3     True
index4    False
index5    False
dtype: bool

應用:取非空值的行

frame3[frame3.isnull().any(axis = 1)==False]
column1column2column3column4
index10.01.02.03.0
index24.05.06.07.0
index412.013.014.015.0
index516.017.018.019.0

應用:取有空值的行

frame3[frame3.isnull().any(axis = 1)==True]
column1column2column3column4
index38.09.010.0NaN

總結

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。 

相關文章

最新評論