liveBook · Manning

Header parameter

As explained in Pandas Workout: 200 exercises to make you a stronger data analyst

The header parameter specifies which input line contains column names or indicates that the input has no header.

The pandas header parameter tells read_csv how to interpret the input’s first lines: use a line as column names, or treat the input as having no header. section 3.13

Choose the setting according to the file’s structure:

  • Omit header to let read_csv treat the first line as column names. section 3.13
  • Use header=None when every line is data and the file supplies no column names. section 1.23 section 3.13
  • Pass an integer when headers appear on a later line rather than the first. section 3.13

Reading a one-column data file

s = pd.read_csv('data/taxi-passenger-count.csv', header=None).squeeze() reads the first line as a passenger-count value rather than a column label, then squeeze converts the one-column data frame into a Series. section 1.23

s = pd.read_csv('data/taxi-passenger-count.csv',
        header=None).squeeze()

Inspect the compact read_csv call that preserves every input line as data. section 1.23

How Pandas Workout: 200 exercises to make you a stronger data analyst covers it

How deep it goes
Defines default, None, and integer settings, but does not detail parser internals.
Examples
Uses a taxi passenger-count file and a passwd-style file without headers.
What it assumes
Assumes familiarity with pandas read_csv and basic data-frame or Series concepts.
What you can do after
Operate read_csv to preserve data rows or select a later header line during import.
How it connects
Links read_csv with CSV files, data frames, Series, column names, and file parsing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pandas Workout: 200 exercises to make you a stronger data analyst. The section links point to the parts of the book it draws on.