Python Pandas read_excel doesn't recognize null cell

前端 未结 1 659
灰色年华
灰色年华 2020-12-21 02:51

My excel sheet:

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

Python code:

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


        
相关标签:
1条回答
  • 2020-12-21 03:07

    For me works parameter 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
    
    0 讨论(0)
提交回复
热议问题