Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.Series.str.join#

Series.str.join(sep)[source]#

Join lists contained as elements in the Series/Index with passed delimiter.

If the elements of a Series are lists themselves, join the content of theselists using the delimiter passed to the function.This function is an equivalent tostr.join().

Parameters:
sepstr

Delimiter to use between list entries.

Returns:
Series/Index: object

The list entries concatenated by intervening occurrences of thedelimiter.

Raises:
AttributeError

If the supplied Series contains neither strings nor lists.

See also

str.join

Standard library version of this method.

Series.str.split

Split strings around given separator/delimiter.

Notes

If any of the list items is not a string object, the result of the joinwill beNaN.

Examples

Example with a list that contains non-string elements.

>>>s=pd.Series([['lion','elephant','zebra'],...[1.1,2.2,3.3],...['cat',np.nan,'dog'],...['cow',4.5,'goat'],...['duck',['swan','fish'],'guppy']])>>>s0        [lion, elephant, zebra]1                [1.1, 2.2, 3.3]2                [cat, nan, dog]3               [cow, 4.5, goat]4    [duck, [swan, fish], guppy]dtype: object

Join all lists using a ‘-’. The lists containing object(s) of types otherthan str will produce a NaN.

>>>s.str.join('-')0    lion-elephant-zebra1                    NaN2                    NaN3                    NaN4                    NaNdtype: object

[8]ページ先頭

©2009-2025 Movatter.jp