regex Filtering | Teradata Python Package - 17.00 - regex Filtering - Teradata Package for Python

Teradata® Package for Python User Guide

Product
Teradata Package for Python
Release Number
17.00
Release Date
November 2021
Content Type
User Guide
Publication ID
B700-4006-070K
Language
English (United States)

Example 1: Filtering with axis set to 'columns' or 1

When axis is 'columns' or 1, then the regex pattern is applied to the column names of the DataFrame.

>>> df.filter(regex='[a-z].*s', axis = 'columns')
  masters     stats
0     yes  Advanced
1     yes    Novice
2     yes    Novice
3      no  Advanced
4      no  Advanced
5     yes  Advanced
6     yes  Advanced
7      no    Novice
8     yes  Advanced
9     yes    Novice

Example 2: Filtering with axis set to 'rows' or 0

When axis is 'rows' or 0, then the regex pattern is applied to the values of the columns specified in the index_label of the DataFrame.
The index columns will be cast into VARCHAR columns in order to perform the match.
>>> df.filter(regex = '^Beg.+', axis = 0)
             id masters   gpa     stats admitted
programming                                    
Beginner     21      no  3.87    Novice        1
Beginner     22     yes  3.46    Novice        0
Beginner     39     yes  3.75  Advanced        0
Beginner     34     yes  3.85  Advanced        0
Beginner     38     yes  2.65  Advanced        1
Beginner      3      no  3.70    Novice        1
Beginner      1     yes  3.95  Beginner        0
Beginner     32     yes  3.46  Advanced        0
Beginner     40     yes  3.95    Novice        0
Beginner     29     yes  4.00    Novice        0