Detail: Frame: Accessor Regular Expression

Overview: Frame: Accessor Regular Expression

Frame.via_re(pattern, flags).match(pos, endpos)
via_re = <function Frame.via_re>[source]
InterfaceRe.match(pos=0, endpos=None)[source]

If zero or more characters at the beginning of string match this regular expression return True, else False. Note that this is different from a zero-length match.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('[X123]').match()
<Frame: x>
<Index>    a      b      c      <<U1>
<Index>
0          True   False  True
1          True   True   True
2          False  True   True
3          True   False  True
<int64>    <bool> <bool> <bool>
Frame.via_re(pattern, flags).fullmatch(pos, endpos)
via_re = <function Frame.via_re>[source]
InterfaceRe.fullmatch(pos=0, endpos=None)[source]

If the whole string matches this regular expression, return True, else False. Note that this is different from a zero-length match.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('123').fullmatch()
<Frame: x>
<Index>    a      b      c      <<U1>
<Index>
0          False  False  False
1          False  False  False
2          False  True   False
3          False  False  False
<int64>    <bool> <bool> <bool>
Frame.via_re(pattern, flags).split(maxsplit)
via_re = <function Frame.via_re>[source]
InterfaceRe.split(maxsplit=0)[source]

Split string by the occurrences of pattern. If capturing parentheses are used in pattern, then the text of all groups in the pattern are also returned as part of the resulting tuple.

Parameters:

maxsplit – If nonzero, at most maxsplit splits occur, and the remainder of the string is returned as the final element of the tuple.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('[X123]').split()
<Frame: x>
<Index>    a         b                c                    <<U1>
<Index>
0          ('', '0') ('qrs ',)        ('', '5', '7-0', ...
1          ('', '')  ('', 'YZ')       ('', '5', '7-04-0...
2          ('8',)    ('', '', '', '') ('', '5', '7-', '...
3          ('', '')  (' w', ' ')      ('', '5', '7-06-'...
<int64>    <object>  <object>         <object>
Frame.via_re(pattern, flags).findall(pos, endpos)
via_re = <function Frame.via_re>[source]
InterfaceRe.findall(pos=0, endpos=None)[source]

Return all non-overlapping matches of pattern in string, as a tuple of strings. The string is scanned left-to-right, and matches are returned in the order found. If one or more groups are present in the pattern, return a tuple of groups; this will be a tuple of tuples if the pattern has more than one group. Empty matches are included in the result.

Parameters:
  • pos – Gives an index in the string where the search is to start; it defaults to 0.

  • endpos – Limits how far the string will be searched; it will be as if the string is endpos characters long.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('[X123]').findall()
<Frame: x>
<Index>    a        b               c                    <<U1>
<Index>
0          ('1',)   ()              ('1', '1', '1', '1')
1          ('2',)   ('X',)          ('1', '1', '1')
2          ()       ('1', '2', '3') ('1', '1', '1', '...
3          ('3',)   ('X',)          ('1', '1', '3')
<int64>    <object> <object>        <object>
Frame.via_re(pattern, flags).sub(repl, count)
via_re = <function Frame.via_re>[source]
InterfaceRe.sub(repl, count=0)[source]

Return the string obtained by replacing the leftmost non-overlapping occurrences of pattern in string by the replacement repl. If the pattern is not found, the string is returned unchanged.

Parameters:
  • repl – A string or a function; if it is a string, any backslash escapes in it are processed.

  • count – The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, all occurrences will be replaced.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('[X123]').sub('==')
<Frame: x>
<Index>    a     b      c                <<U1>
<Index>
0          ==0   qrs    ==5==7-0==-0==
1          ==    ==YZ   ==5==7-04-0==
2          8     ====== ==5==7-====-====
3          ==     w==   ==5==7-06-==0
<int64>    <<U3> <<U6>  <<U16>
Frame.via_re(pattern, flags).subn(repl, count)
via_re = <function Frame.via_re>[source]
InterfaceRe.subn(repl, count=0)[source]

Perform the same operation as sub(), but return a tuple (new_string, number_of_subs_made).

Parameters:
  • repl – A string or a function; if it is a string, any backslash escapes in it are processed.

  • count – The optional argument count is the maximum number of pattern occurrences to be replaced; count must be a non-negative integer. If omitted or zero, all occurrences will be replaced.

>>> f = sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')
>>> f
<Frame: x>
<Index>    a       b     c               <<U1>
<Index>
0          10      qrs   1517-01-01
1          2       XYZ   1517-04-01
2          8       123   1517-12-31
3          3        wX   1517-06-30
<int64>    <int64> <<U4> <datetime64[D]>
>>> f.via_re('[X123]').subn('==', 1)
<Frame: x>
<Index>    a          b            c                  <<U1>
<Index>
0          ('==0', 1) ('qrs ', 0)  ('==517-01-01', 1)
1          ('==', 1)  ('==YZ', 1)  ('==517-04-01', 1)
2          ('8', 0)   ('==23', 1)  ('==517-12-31', 1)
3          ('==', 1)  (' w== ', 1) ('==517-06-30', 1)
<int64>    <object>   <object>     <object>

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