Skip to content

dataframe.read_csv misinterprets pandas-generated column names #878

Closed

Description

@sscondie

In version 0.7.5, when reading in a CSV file that has numerical column names assigned by pandas, dask.dataframe.read_csv misinterprets the column names that have been assigned by pandas.

In particular, the column names (in the code sample ",0,1,2") given on the first row are interpreted as the first row of data by dask.dataframe.read_csv whereas they are correctly identified as column names by the pandas.read_csv method.

See the attached file for a minimal code sample that reproduces the error.

Activity

  1. mrocklin commented on Jan 22, 2016

    @mrocklin
    Member

    Sorry for leaving this for so long. It slipped down my e-mail.

    I don't see an attached file.

    The following is my experience:

    In [1]: import pandas as pd
    df
    In [2]: import numpy as np
    
    In [3]: pd.DataFrame(np.random.random((10, 4))).to_csv('foo.csv')
    
    In [4]: !cat foo.csv
    ,0,1,2,3
    0,0.13431684284337342,0.28371864338584785,0.09408808481184705,0.4509063714136845
    1,0.3628017386057968,0.5130729393279804,0.2575872885550655,0.03026520906455976
    2,0.6613515196180496,0.04368417377557987,0.02645654556785726,0.0776708120231967
    3,0.7957849970368974,0.9167022276900998,0.5903091867964598,0.7432588833806314
    4,0.18098615421662856,0.9643215759266229,0.6904862552351742,0.5721408777218844
    5,0.6010285891123545,0.3999564088456772,0.22616548958242277,0.8348176377338515
    6,0.7634511108227137,0.3390152599050831,0.8113770724433769,0.24687632720234998
    7,0.7449335432579999,0.18933549591859888,0.4551595642930776,0.7067760231110608
    8,0.6667867411131122,0.42469493786906454,0.13576929024782391,0.25320611470011445
    9,0.9611310794078418,0.968875650472187,0.712468515165838,0.1267005359114427
    
    In [5]: import dask.dataframe as dd
    
    In [6]: df = dd.read_csv('foo.csv', header=True)
    /home/mrocklin/Software/anaconda/lib/python3.4/site-packages/pandas-0.17.0rc1+303.geb66bcc-py3.4-linux-x86_64.egg/pandas/io/common.py in _validate_header_arg(header)
        214 def _validate_header_arg(header):
        215     if isinstance(header, bool):
    --> 216         raise TypeError("Passing a bool to header is invalid. "
        217                         "Use header=None for no header or "
        218                         "header=int or list-like of ints to specify "
    
    TypeError: Passing a bool to header is invalid. Use header=None for no header or header=int or list-like of ints to specify the row(s) making up the column names
    
    In [7]: df = dd.read_csv('foo.csv', header=0)
    
    In [8]: df.head()
    Out[8]: 
       Unnamed: 0         0         1         2         3
    0           0  0.134317  0.283719  0.094088  0.450906
    1           1  0.362802  0.513073  0.257587  0.030265
    2           2  0.661352  0.043684  0.026457  0.077671
    3           3  0.795785  0.916702  0.590309  0.743259
    4           4  0.180986  0.964322  0.690486  0.572141

    Does this workflow work for you?

  2. mrocklin commented on Apr 26, 2016

    @mrocklin
    Member

    Closing until more information arrives.

  3. added a commit that references this issue on Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions