janitor.row_to_names

janitor.row_to_names(df: pandas.core.frame.DataFrame, row_number: int = None, remove_row: bool = False, remove_rows_above: bool = False) → pandas.core.frame.DataFrame[source]

Elevates a row to be the column names of a DataFrame.

This method mutates the original DataFrame.

Contains options to remove the elevated row from the DataFrame along with removing the rows above the selected row.

Method chaining usage:

df = (
    pd.DataFrame(...)
    .row_to_names(
        row_number=0,
        remove_row=False,
        remove_rows_above=False,
    )
)
Parameters
  • df – A pandas DataFrame.

  • row_number – The row containing the variable names

  • remove_row – Whether the row should be removed from the DataFrame. Defaults to False.

  • remove_rows_above – Whether the rows above the selected row should be removed from the DataFrame. Defaults to False.

Returns

A pandas DataFrame with set column names.