Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.str.wrap#

Series.str.wrap(width,**kwargs)[source]#

Wrap strings in Series/Index at specified line width.

This method has the same keyword parameters and defaults astextwrap.TextWrapper.

Parameters:
widthint

Maximum line width.

expand_tabsbool, optional

If True, tab characters will be expanded to spaces (default: True).

replace_whitespacebool, optional

If True, each whitespace character (as defined by string.whitespace)remaining after tab expansion will be replaced by a single space(default: True).

drop_whitespacebool, optional

If True, whitespace that, after wrapping, happens to end up at thebeginning or end of a line is dropped (default: True).

break_long_wordsbool, optional

If True, then words longer than width will be broken in order to ensurethat no lines are longer than width. If it is false, long words willnot be broken, and some lines may be longer than width (default: True).

break_on_hyphensbool, optional

If True, wrapping will occur preferably on whitespace and right afterhyphens in compound words, as it is customary in English. If false,only whitespaces will be considered as potentially good places for linebreaks, but you need to set break_long_words to false if you want trulyinsecable words (default: True).

Returns:
Series or Index

Notes

Internally, this method uses atextwrap.TextWrapper instance withdefault settings. To achieve behavior matching R’s stringr library str_wrapfunction, use the arguments:

  • expand_tabs = False

  • replace_whitespace = True

  • drop_whitespace = True

  • break_long_words = False

  • break_on_hyphens = False

Examples

>>>s=pd.Series(['line to be wrapped','another line to be wrapped'])>>>s.str.wrap(12)0             line to be\nwrapped1    another line\nto be\nwrappeddtype: object

[8]ページ先頭

©2009-2025 Movatter.jp