Python Pandas read_excel 无法识别空单元格

Python Pandas read_excel doesn't recognize null cell

我的excelsheet:

   A   B  
1 first second
2
3 
4  x   y  
5  z   j

Python代码:

df = pd.read_excel (filename, parse_cols=1)

return 一个正确的输出:

  first second
0 NaN   NaN
1 NaN   NaN
2 x     y
3 z     j

如果我只想使用第二列

df = pd.read_excel (filename, parse_cols=[1])

return:

 second
0  y
1  j

即使我只处理特定的列,我也会有关于空 excel 行(我的 df 中的 NaN)的信息。 如果输出松散的 NaN 信息是不行的,例如对于 skiprows 参数等

谢谢

对我来说工作参数skip_blank_lines=False:

df = pd.read_excel ('test.xlsx', 
                     parse_cols=1, 
                     skip_blank_lines=False)
print (df)

       A       B
0  first  second
1    NaN     NaN
2    NaN     NaN
3      x       y
4      z       j

或者如果需要省略第一行:

df = pd.read_excel ('test.xlsx', 
                     parse_cols=1, 
                     skiprows=1,
                     skip_blank_lines=False)
print (df)

  first second
0   NaN    NaN
1   NaN    NaN
2     x      y
3     z      j