Skip to content

BUG/ERR: read_csv(header=[0]) should raise/warn #7757

Closed
@ischwabacher

Description

@ischwabacher

read_csv with a single-row header either breaks any names that might be on the index, or reads all data as NaN. This problem might exist because pd.read_csv hasn't caught up to #7589.

In [1]: import pandas as pd

In [2]: from StringIO import StringIO

In [3]: pd.read_csv(StringIO('''\
alpha,,A,B
foo,bar,,
this,x,1,2
this,y,5,6
that,x,3,4
that,y,7,8'''), header=0, index_col=[0,1])
Out[3]: 
                   A   B
alpha Unnamed: 1        
foo   bar        NaN NaN
this  x            1   2
      y            5   6
that  x            3   4
      y            7   8

In [4]: pd.read_csv(StringIO('''\
alpha,,A,B
foo,bar,,
this,x,1,2
this,y,5,6
that,x,3,4
that,y,7,8'''), header=[0], index_col=[0,1])
Out[4]: 
alpha       A    B
foo  bar          
this x    NaN  NaN
     y    NaN  NaN
that x    NaN  NaN
     y    NaN  NaN

In [5]: pd.read_csv(StringIO('''\
alpha,,A,B
beta,,Y,Z
foo,bar,,
this,x,1,2
this,y,5,6
that,x,3,4                                  
that,y,7,8'''), header=[0,1], index_col=[0,1])
Out[5]: 
alpha     A  B
beta      Y  Z
foo  bar      
this x    1  2
     y    5  6
that x    3  4
     y    7  8

Metadata

Metadata

Assignees

No one assigned

    Labels

    Error ReportingIncorrect or improved errors from pandasIO CSVread_csv, to_csv

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions