python
问题描述:
在excel表格中显示none单元格我正在处理Excel表格和python的问题。我已成功检索了由熊猫在Excel中的特定列和行。现在我只想显示具有“无”或“空”值的行和列。 excel表的示例图像python
在上图中,我需要行和列的值为无。例如在“estfix”列中有几个没有值,所以我需要检查列值,如果它不是我需要打印它的相应的行和列。希望你能理解。
代码我想:
import pandas as pd
wb= pd.ExcelFile(r"pathname details.xlsx")
sheet_1=pd.read_excel(r"pathname details.xlsx",sheetname=0)
c=sheet_1[["bugid","sev","estfix","manager","director"]]
print(c)
我使用python 3.6。提前致谢!
这里楠被认为是一个无。
答
a = df[df.isnull().any(axis=1)]
对于列与列:
b = df.loc[df.isnull().any(axis=1), df.isnull().any()]
样品:
df = pd.DataFrame({'A':list('abcdef'),
'B':[4,np.nan,4,5,5,4],
'C':[7,8,9,4,2,3],
'D':[1,3,np.nan,7,1,0],
'E':[5,3,6,9,2,4],
'F':list('aaabbb')})
print (df)
A B C D E F
0 a 4.0 7 1.0 5 a
1 b NaN 8 3.0 3 a
2 c 4.0 9 NaN 6 a
3 d 5.0 4 7.0 9 b
4 e 5.0 2 1.0 2 b
5 f 4.0 3 0.0 4 b
a = df[df.isnull().any(1)]
print (a)
A B C D E F
1 b NaN 8 3.0 3 a
2 c 4.0 9 NaN 6 a
b = df.loc[df.isnull().any(axis=1), df.isnull().any()]
print (b)
B D
1 NaN 3.0
2 4.0 NaN
详细信息:
print (df.isnull())
A B C D E F
0 False False False False False False
1 False True False False False False
2 False False False True False False
3 False False False False False False
4 False False False False False False
5 False False False False False False
print (df.isnull().any(axis=1))
0 False
1 True
2 True
3 False
4 False
5 False
dtype: bool
print (df.isnull().any())
A False
B True
C False
D True
E False
F False
dtype: bool