pandas.Series.str.pad

pandas 3.1.1 · Series and accessors · method

Pad each string to a minimum width on the requested side or sides.

Call syntax

Series.str.pad(width, side='left', fillchar=' ')

Run the example

Edit the example and select Run Python to see the result.

Parameters

ParameterRequirementAccepted values and behavior
width Required
Positional or keyword
int

Set the requested width of the formatted result.

side Optional
Positional or keyword
Default 'left'
{'left', 'right', 'both'}

Choose the side of the search, interval, or padding operation.

fillchar Optional
Positional or keyword
Default ' '
str

Choose the character used to pad strings.

Returns

Series or Index of object