Detail: Series: Accessor String

Overview: Series: Accessor String

Series.via_str.__getitem__(key)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.__getitem__(key)[source]

Return a container with the provided selection or slice of each element.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str[-1]
<Series>
<Index>
a
b        Z
c        3
d
<<U1>    <<U1>
Series.via_str.capitalize
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.capitalize()[source]

Return a container with only the first character of each element capitalized.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.capitalize()
<Series>
<Index>
a        Qrs
b        Xyz
c        123
d         wx
<<U1>    <<U4>
Series.via_str.center(width, fillchar)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.center(width, fillchar=' ')[source]

Return a container with its elements centered in a string of length width.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.center(8)
<Series>
<Index>
a          qrs
b          XYZ
c          123
d           wX
<<U1>    <<U8>
Series.via_str.contains(item)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.contains(item)[source]

Return a Boolean container showing True of item is a substring of elements.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.contains('X')
<Series>
<Index>
a        False
b        True
c        False
d        True
<<U1>    <bool>
Series.via_str.count(sub, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.count(sub, start=None, end=None)[source]

Returns a container with the number of non-overlapping occurrences of substring sub in the optional range start, end.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.count('X')
<Series>
<Index>
a        0
b        1
c        0
d        1
<<U1>    <int64>
Series.via_str.decode(encoding, errors)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.decode(encoding=None, errors=None)[source]

Apply str.decode() to each element. Elements must be bytes.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd')).astype(bytes)
>>> s
<Series>
<Index>
a        b'qrs '
b        b'XYZ'
c        b'123'
d        b' wX '
<<U1>    <|S4>
>>> s.via_str.decode()
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
Series.via_str.encode(encoding, errors)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.encode(encoding=None, errors=None)[source]

Apply str.encode() to each element. Elements must be strings.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.encode()
<Series>
<Index>
a        b'qrs '
b        b'XYZ'
c        b'123'
d        b' wX '
<<U1>    <|S4>
Series.via_str.endswith(suffix, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.endswith(suffix, start=None, end=None)[source]

Returns a container with the number of non-overlapping occurrences of substring suffix (or an iterable of suffixes) in the optional range start, end.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.endswith(' ')
<Series>
<Index>
a        True
b        False
c        False
d        True
<<U1>    <bool>
Series.via_str.find(sub, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.find(sub, start=None, end=None)[source]

For each element, return the lowest index in the string where substring sub is found.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.find('X')
<Series>
<Index>
a        -1
b        0
c        -1
d        2
<<U1>    <int64>
Series.via_str.format(format)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.format(format)[source]

For each element, return a string resulting from calling the string format argument’s format method with the the element. Format strings (given within curly braces) can use Python’s format mini language: https://docs.python.org/3/library/string.html#formatspec

Parameters:

format – A string, an iterable of strings, or a mapping of labels to strings. For 1D containers, an iterable of strings must be of length equal to the container; a mapping can use Index labels (for a Series) or positions (for an Index). For 2D containers, an iterable of strings must be of length equal to the columns (for a Frame) or the depth (for an Index Hierarchy); a mapping can use column labels (for a Frame) or depths (for an IndexHierarchy).

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.format('{:-^10}')
<Series>
<Index>
a        ---qrs ---
b        ---XYZ----
c        ---123----
d        --- wX ---
<<U1>    <<U10>
Series.via_str.index(sub, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.index(sub, start=None, end=None)[source]

Like find, but raises ValueError when the substring is not found.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.index('X')
ValueError('substring not found')
Series.via_str.isalnum
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isalnum()[source]

Returns true for each element if all characters in the string are alphanumeric and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isalnum()
<Series>
<Index>
a        False
b        True
c        True
d        False
<<U1>    <bool>
Series.via_str.isalpha
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isalpha()[source]

Returns true for each element if all characters in the string are alphabetic and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isalpha()
<Series>
<Index>
a        False
b        True
c        False
d        False
<<U1>    <bool>
Series.via_str.isdecimal
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isdecimal()[source]

For each element, return True if there are only decimal characters in the element.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isdecimal()
<Series>
<Index>
a        False
b        False
c        True
d        False
<<U1>    <bool>
Series.via_str.isdigit
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isdigit()[source]

Returns true for each element if all characters in the string are digits and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isdigit()
<Series>
<Index>
a        False
b        False
c        True
d        False
<<U1>    <bool>
Series.via_str.islower
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.islower()[source]

Returns true for each element if all cased characters in the string are lowercase and there is at least one cased character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.islower()
<Series>
<Index>
a        True
b        False
c        False
d        False
<<U1>    <bool>
Series.via_str.isnumeric
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isnumeric()[source]

For each element in self, return True if there are only numeric characters in the element.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isnumeric()
<Series>
<Index>
a        False
b        False
c        True
d        False
<<U1>    <bool>
Series.via_str.isspace
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isspace()[source]

Returns true for each element if there are only whitespace characters in the string and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isspace()
<Series>
<Index>
a        False
b        False
c        False
d        False
<<U1>    <bool>
Series.via_str.istitle
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.istitle()[source]

Returns true for each element if the element is a titlecased string and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.istitle()
<Series>
<Index>
a        False
b        False
c        False
d        False
<<U1>    <bool>
Series.via_str.isupper
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.isupper()[source]

Returns true for each element if all cased characters in the string are uppercase and there is at least one character, false otherwise.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.isupper()
<Series>
<Index>
a        False
b        True
c        False
d        False
<<U1>    <bool>
Series.via_str.ljust(width, fillchar)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.ljust(width, fillchar=' ')[source]

Return a container with its elements ljusted in a string of length width.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.ljust(8)
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U8>
Series.via_str.len
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.len()[source]

Return the length of the string.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.len()
<Series>
<Index>
a        4
b        3
c        3
d        4
<<U1>    <int64>
Series.via_str.lower
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.lower()[source]

Return an array with the elements of self converted to lowercase.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.lower()
<Series>
<Index>
a        qrs
b        xyz
c        123
d         wx
<<U1>    <<U4>
Series.via_str.lstrip(chars)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.lstrip(chars=None)[source]

For each element, return a copy with the leading characters removed.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.lstrip()
<Series>
<Index>
a        qrs
b        XYZ
c        123
d        wX
<<U1>    <<U4>
Series.via_str.partition(sep)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.partition(sep)[source]

Partition each element around sep.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.partition('X')
<Series>
<Index>
a        ('qrs ', '', '')
b        ('', 'X', 'YZ')
c        ('123', '', '')
d        (' w', 'X', ' ')
<<U1>    <object>
Series.via_str.replace(old, new, count)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.replace(old, new, count=None)[source]

Return a container with its elements replaced in a string of length width.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.replace('X', '*')
<Series>
<Index>
a        qrs
b        *YZ
c        123
d         w*
<<U1>    <<U4>
Series.via_str.rfind(sub, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rfind(sub, start=None, end=None)[source]

For each element, return the highest index in the string where substring sub is found, such that sub is contained within start, end.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rfind('X')
<Series>
<Index>
a        -1
b        0
c        -1
d        2
<<U1>    <int64>
Series.via_str.rindex(sub, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rindex(sub, start=None, end=None)[source]

Like rfind, but raises ValueError when the substring sub is not found.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rindex('X')
ValueError('substring not found')
Series.via_str.rjust(width, fillchar)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rjust(width, fillchar=' ')[source]

Return a container with its elements rjusted in a string of length width.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rjust(8)
<Series>
<Index>
a            qrs
b             XYZ
c             123
d             wX
<<U1>    <<U8>
Series.via_str.rpartition(sep)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rpartition(sep)[source]

Partition (split) each element around the right-most separator.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rpartition('X')
<Series>
<Index>
a        ('', '', 'qrs ')
b        ('', 'X', 'YZ')
c        ('', '', '123')
d        (' w', 'X', ' ')
<<U1>    <object>
Series.via_str.rsplit(sep, maxsplit)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rsplit(sep, maxsplit=-1)[source]

For each element, return a tuple of the words in the string, using sep as the delimiter string.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rsplit('X')
<Series>
<Index>
a        ('qrs ',)
b        ('', 'YZ')
c        ('123',)
d        (' w', ' ')
<<U1>    <object>
Series.via_str.rstrip(chars)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.rstrip(chars=None)[source]

For each element, return a copy with the trailing characters removed.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.rstrip()
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
Series.via_str.split(sep, maxsplit)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.split(sep, maxsplit=-1)[source]

For each element, return a tuple of the words in the string, using sep as the delimiter string.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.split('X')
<Series>
<Index>
a        ('qrs ',)
b        ('', 'YZ')
c        ('123',)
d        (' w', ' ')
<<U1>    <object>
Series.via_str.startswith(prefix, start, end)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.startswith(prefix, start=None, end=None)[source]

Returns a container with the number of non-overlapping occurrences of substring prefix (or an iterable of prefixes) in the optional range start, end.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.startswith('X')
<Series>
<Index>
a        False
b        True
c        False
d        False
<<U1>    <bool>
Series.via_str.strip(chars)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.strip(chars=None)[source]

For each element, return a copy with the leading and trailing characters removed.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.strip()
<Series>
<Index>
a        qrs
b        XYZ
c        123
d        wX
<<U1>    <<U4>
Series.via_str.swapcase
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.swapcase()[source]

Return a container with uppercase characters converted to lowercase and vice versa.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.swapcase()
<Series>
<Index>
a        QRS
b        xyz
c        123
d         Wx
<<U1>    <<U4>
Series.via_str.title
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.title()[source]

Return a container with uppercase characters converted to lowercase and vice versa.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.title()
<Series>
<Index>
a        Qrs
b        Xyz
c        123
d         Wx
<<U1>    <<U4>
Series.via_str.upper
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.upper()[source]

Return a container with uppercase characters converted to lowercase and vice versa.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.upper()
<Series>
<Index>
a        QRS
b        XYZ
c        123
d         WX
<<U1>    <<U4>
Series.via_str.zfill(width)
Series.via_str

Interface for applying string methods to elements in this container.

InterfaceString.zfill(width)[source]

Return the string left-filled with zeros.

>>> s = sf.Series(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd'))
>>> s
<Series>
<Index>
a        qrs
b        XYZ
c        123
d         wX
<<U1>    <<U4>
>>> s.via_str.zfill(8)
<Series>
<Index>
a        0000qrs
b        00000XYZ
c        00000123
d        0000 wX
<<U1>    <<U8>

Series: Constructor | Exporter | Attribute | Method | Dictionary-Like | Display | Assignment | Selector | Iterator | Operator Binary | Operator Unary | Accessor Values | Accessor Datetime | Accessor String | Accessor Fill Value | Accessor Regular Expression | Accessor Hashlib | Accessor Type Clinic