My excel sheet:
我的excel表:
A B
1 first second
2
3
4 x y
5 z j
Python code:
Python代码:
df = pd.read_excel (filename, parse_cols=1)
return a correct output:
返回一个正确的输出:
first second
0 NaN NaN
1 NaN NaN
2 x y
3 z j
If i want work only with second column
如果我想只对第二列做功
df = pd.read_excel (filename, parse_cols=[1])
return:
返回:
second
0 y
1 j
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
我将获得关于空excel行(在我的df中是NaN)的信息,即使我只使用特定的列。如果输出松散的NaN信息,例如,对于skiprows参数,等等是不允许的
Thanks
谢谢
1 个解决方案
#1
5
For me works parameter skip_blank_lines=False
:
我的工作参数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
#1
5
For me works parameter skip_blank_lines=False
:
我的工作参数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