Skip to content

set_axis with callable #29145

Open
Open
@markxwang

Description

@markxwang

Hi,
I've been using method chaining to write most of my data wrangling processes and one of the things that bother me a bit is to modify column names as part of the chain.

With a static list of column names, df.set_axis can do the work. But in the following cases, I have to use df.columns=xxx to modify the names.

  1. Header comes from a row
  2. Combine multi-indexed header into a single-index (e.g. concatenate levels)
  3. Expand single-indexed header to multi-indexed (e.g. split via some delimiter)

I wonder if these could be achieved by allowing df.set_axis to take callables, something similar to df.assign.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions