通过 python 在 excel sheet 中显示 none 单元格
To display the none cell in the excel sheet by python
我正在处理 Excel sheet 和 python 的问题。我已通过 pandas 成功检索到 Excel 中的特定列和行。现在我只想显示具有 "none" 或 "empty" 值的行和列。 excelsheet
的示例图片
在上图中,我需要值为none的行和列。例如在 "estfix" 列中有几个 none 值,所以我需要检查列值,如果它是 none 我需要打印它对应的行和列。希望你明白。
我试过的代码:
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。提前致谢!
我期待这样的输出:
这里 Nan 被认为是 None。
使用 isnull
with any
检查至少一个 True:
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
我正在处理 Excel sheet 和 python 的问题。我已通过 pandas 成功检索到 Excel 中的特定列和行。现在我只想显示具有 "none" 或 "empty" 值的行和列。 excelsheet
在上图中,我需要值为none的行和列。例如在 "estfix" 列中有几个 none 值,所以我需要检查列值,如果它是 none 我需要打印它对应的行和列。希望你明白。
我试过的代码:
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。提前致谢!
我期待这样的输出:
这里 Nan 被认为是 None。
使用 isnull
with any
检查至少一个 True:
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