Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.str.pad#

Series.str.pad(width,side='left',fillchar='')[source]#

Pad strings in the Series/Index up to width.

Parameters:
widthint

Minimum width of resulting string; additional characters will be filledwith character defined infillchar.

side{‘left’, ‘right’, ‘both’}, default ‘left’

Side from which to fill resulting string.

fillcharstr, default ‘ ‘

Additional character for filling, default is whitespace.

Returns:
Series or Index of object

Returns Series or Index with minimum number of char in object.

See also

Series.str.rjust

Fills the left side of strings with an arbitrary character. Equivalent toSeries.str.pad(side='left').

Series.str.ljust

Fills the right side of strings with an arbitrary character. Equivalent toSeries.str.pad(side='right').

Series.str.center

Fills both sides of strings with an arbitrary character. Equivalent toSeries.str.pad(side='both').

Series.str.zfill

Pad strings in the Series/Index by prepending ‘0’ character. Equivalent toSeries.str.pad(side='left',fillchar='0').

Examples

>>>s=pd.Series(["caribou","tiger"])>>>s0    caribou1      tigerdtype: object
>>>s.str.pad(width=10)0       caribou1         tigerdtype: object
>>>s.str.pad(width=10,side='right',fillchar='-')0    caribou---1    tiger-----dtype: object
>>>s.str.pad(width=10,side='both',fillchar='-')0    -caribou--1    --tiger---dtype: object

[8]ページ先頭

©2009-2025 Movatter.jp