Skip to content

header='infer' is not working when there is no header #17483

Closed
@gokceneraslan

Description

@gokceneraslan

Code Sample

import tempfile
import pandas as pd

df = pd.DataFrame({'AAA' : [4,5,6,7], 'BBB' : [10,20,30,40],'CCC' : [100,50,-30,-50]})
tmp = tempfile.mkstemp()[1]
df.to_csv(tmp, header=False)
df = pd.read_csv(tmp, header='infer')
print(df)

Output

0 | 4 | 10 | 100
--| --| -- | --
1 | 5 | 20 | 50
2 | 6 | 30 | -30
3 | 7 | 40 | -50


Pandas cannot infer that there is no header in csv files even though I use header='infer' argument in read_csv.

Expected Output


0 | 1 | 2  | 3
--| --| -- | --
0 | 4 | 10 | 100
1 | 5 | 20 | 50
2 | 6 | 30 | -30
3 | 7 | 40 | -50

I expect header inference to work properly and return a dataframe with 4 rows here. See data.table R package for a working header inference implementation[1].

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.20.3
pytest: 3.2.1
pip: 9.0.1
setuptools: 27.2.0
Cython: 0.26
numpy: 1.13.1
scipy: 0.19.1
xarray: None
IPython: 6.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
pandas_gbq: None
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions