I have a dataframe in which some rows contain missing values.
In [31]: df.head()
Out[31]:
alpha1 alpha2 gamma1 gamma2 chi2min
filename
M66_MI_NSRh35d32kpoints.dat 0.8016 0.9283 1.000000 0.074804 3.985599e+01
F71_sMI_DMRI51d.dat 0.0000 0.0000 NaN 0.000000 1.000000e+25
F62_sMI_St22d7.dat 1.7210 3.8330 0.237480 0.150000 1.091832e+01
F41_Car_HOC498d.dat 1.1670 2.8090 0.364190 0.300000 7.966335e+00
F78_MI_547d.dat 1.8970 5.4590 0.095319 0.100000 2.593468e+01
I want to display those rows on the screen. If I try df.isnull()
, it gives a long dataframe with True
and False
. Is there any way by which I can select these rows and print them on the screen?
You can use
DataFrame.any
with parameteraxis=1
for check at least oneTrue
in row byDataFrame.isna
withboolean indexing
:Explanation:
Suppose gamma1 and gamma2 are two such columns for which df.isnull().any() gives True value , the following code can be used to print the rows.
Use
df[df.isnull().any(axis=1)]
for python 3.6 or above.