Skip to content

ENH: Add Series.str.format method #59356

Open
@luxedo

Description

@luxedo

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

Many times I wanted to convert a float column into percentage but it's very verbose. Adding a str.format method would make it easy to convert any numeric columns to percentage and also allow for many other use cases.

Feature Description

    # Series.str class
    def format(self, format_spec: str):
        return self.apply(lambda x: format_spec.format(x))

series.str.format("{:%}")

Alternative Solutions

series.apply(lambda x: "{:%}".format(x))

Additional Context

There's many alternatives for creating formatted strings, but this feature should add the possibility to store the formatted values in pd.Series instead.

I can submit a PR if this idea makes sense.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closing CandidateMay be closeable, needs more eyeballsEnhancementStringsString extension data type and string data

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions