ENH: Ability to name columns/index levels when using .str.split(..., expand=True)
on Index
/Series
#61515
Open
2 of 3 tasks
Labels
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
When using
.str.split(..., expand=True)
:Series
the resulting dataframe columns are labeled with numbers by defaultIndex
the resulting levels are not labeledIt would be great if we could specify the names that the new columns or levels will take once the split is performed.
Feature Description
I think it would be helpful if the method had a
names
parameter that would at a minimum accept a sequence of labels for the newly created columns/levels, similarly to howMultiIndex
is initialized.It could work like so:
The length of the
names
sequence should match the number of expanded columns/levels, otherwise it should throw aValueError
.Alternative Solutions
For
Index
, this works almost exactly the same:So I think it's not as impactful for
Index
.But for
Series
, this becomes more cumbersome, and the need to specify the renaming via a dictionary makes it feel disjointed vs the easier index renaming andMultiIndex
instantiation:So my proposal would provide a similar interface for using the
split
method of thestr
accessor across pandas sequences.Additional Context
No response
The text was updated successfully, but these errors were encountered: