Python Pandas read_excel无法识别空单元格 [英] Python Pandas read_excel doesn't recognize null cell
本文介绍了Python Pandas read_excel无法识别空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Excel工作表:
My excel sheet:
A B
1 first second
2
3
4 x y
5 z j
Python代码:
df = pd.read_excel (filename, parse_cols=1)
返回正确的输出:
first second
0 NaN NaN
1 NaN NaN
2 x y
3 z j
如果我只想处理第二列
df = pd.read_excel (filename, parse_cols=[1])
返回:
second
0 y
1 j
即使我只处理特定的列,我也将获得有关空白excel行(在df中为NaN)的信息. 如果输出松散的NaN信息,则不行,例如,对于跳草参数等,
I'd have information about empty excel rows (NaN in my df) even if I work only with a specific column. If output loose NaN information it's not ok, for example, for skiprows paramater, etc
谢谢
推荐答案
对我来说,参数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
或者如果需要省略第一行:
Or if need omit first row:
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
这篇关于Python Pandas read_excel无法识别空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文