vDataFrame.regexp

In [ ]:
vDataFrame.regexp(column: str,
                  pattern: str,
                  method: str = "substr", 
                  position: int = 1,
                  occurrence: int = 1,
                  replacement: str = '',
                  return_position : int = 0,
                  name: str = "")

Computes a new vcolumn based on regular expressions.

Parameters

Name Type Optional Description
column
str
Input vcolumn to use to compute the regular expression.
pattern
str
The regular expression.
method
str
Method to use to compute the regular expressions.
  • count : Returns the number times a regular expression matches each element of the input vcolumn.
  • ilike : Returns True if the vcolumn element contains a match for the regular expression.
  • instr : Returns the starting or ending position in a vcolumn element where a regular expression matches.
  • like : Returns True if the vcolumn element matches the regular expression.
  • not_ilike : Returns True if the vcolumn element does not match the case-insensitive regular expression.
  • not_like : Returns True if the vcolumn element does not contain a match for the regular expression.
  • replace : Replaces all occurrences of a substring that match a regular expression with another substring.
  • substr : Returns the substring that matches a regular expression within a vcolumn.
position
int
The number of characters from the start of the string where the function should start searching for matches.
occurrence
int
Controls which occurrence of a pattern match in the string to return.
replacement
str
The string to replace matched substrings.
return_position
int
Sets the position within the string to return.
name
str
New feature name. If empty, a name will be generated.

Returns

vDataFrame : self

Example

In [51]:
from verticapy import *
filmtv_movies = vDataFrame("filmtv_movies")
display(filmtv_movies)
Abc
Varchar(1048)
Abc
Varchar(2218)
123
avg_vote
Numeric(6,2)
Abc
Varchar(486)
Abc
Varchar(2232)
Abc
genre
Varchar(22)
Abc
director
Varchar(1066)
123
filmtv_id
Int
123
duration
Int
123
votes
Int
123
year
Numeric(8,2)
Abc
country
Varchar(208)
17.20ComedyBarry Levinson1895151982.00United States
27.80DramaElio Petri22931021967.00Italy
36.50ThrillerRay Morrison (Angelo Dorigo)248031966.00Italy
45.50AdventureLeon Klimovsky3010121968.00Italy
54.00ComedyCarol Wiseman319011990.00United States
65.10DramaJoseph Ruben32961071990.00United States
78.00ThrillerBrian Grant3310021991.00United States
85.90ComedyMarcello Fondato37100421975.00Italy
94.00DramaVera Belmont4111011985.00France
108.00DramaGéza Beremenyi4211011988.00Hungary
116.00DramaIan Sellar468811992.00France, Great Britain
128.30DramaSidney Lumet49110681964.00United States
137.00ActionLiu Chia Yung508821990.00United States, China
144.00AdventureEmilio Miraglia539461968.00Italy
156.60ComedyAlan Metter55100161986.00United States
164.00ComedyNico Mastorakis568911988.00United States
177.10ComedyBruce Beresford581001711989.00United States
184.00DramaMark Rezyka609811987.00Great Britain
197.00WesternSidney J. Furie6198241966.00United States
205.50CrimeMario Caiano63100261975.00Italy
214.00CrimeRomolo Guerrieri648511991.00Italy
224.00ComedyLes Rose659411981.00Canada
236.00ComedyGennaro Righelli6890281945.00Italy
246.00DramaMichael Miller7012011986.00United States
255.20AdventurePeter Yates74130281977.00United States
268.00DramaMilton Katselas7512021979.00United States
276.30BiographyJohn Cromwell7711091940.00United States
283.50ComedyJosé Lopez Rubio, Primo Zeglio828831943.00Italy, Spain
296.50WarGeorg Wilhelm Pabst857521955.00Germany
306.50ComedyAndrew Marton869231962.00United States
317.20ComedyWilliam Dieterle8810451950.00United States
326.00ComedyMichael Schroeder919011988.00United States
336.00ComedyJames Frawley939711980.00United States
344.50DramaChristine Allen947741987.00France
358.00ComedyGero Zambuto966811933.00Italy
365.50DramaNunzio Malasomma1008031942.00Italy
375.10CrimeCraig R. Baxley10197321988.00United States
388.00DramaKoei Oguri10211511990.00Japan
394.00DramaDon Boyd1039211977.00Great Britain
406.50DramaDaniel Mann10710951961.00United States
415.00ComedyMario Mattòli1089071949.00Italy
426.80ComedyHarold French10992111949.00Great Britain
436.70WarFrank Borzage11178161932.00United States
446.00ThrillerJerrold Freedman11310011990.00United States
457.20DramaFerdinando M. Poggioli11488111940.00Italy
466.00DramaWilliam A. Wellman1159531956.00United States
474.00AdventureJack Couffer11610411969.00Great Britain
487.30RomanticSam Wood117114231939.00United States
498.30ComedyAnthony Asquith11890141951.00Great Britain
503.00DramaRoberto Bianchi Montero1198621954.00Italy
518.00DramaDaniel Mann12010411954.00United States
525.30ComedyEdouard Molinaro122108101963.00France
536.10ComedyHoward Zieff123100141984.00United States
546.00ComedyFernandel1258011943.00France
556.00DramaIngmar Bergman12793161971.00Sweden, United States
564.00DramaWilliam Spier, Roy Kellino1288211952.00United States
575.50ComedyPasquale Festa Campanile12995331966.00Italy
585.00ComedyRaffaello Matarazzo1309041963.00Italy
594.80SpyRaoul Levy13610041966.00United States
605.20ComedyJim Abrahams13792201988.00United States
616.50CrimeMike Figgis138112651990.00United States
626.00DramaSharron Miller13910011988.00United States
637.10ComedyRichard Quine14098321962.00United States
646.00DramaLou Antonio1418911991.00United States
655.50AdventureMichele Lupo14595201975.00Italy
664.50AdventureGiovanni Roccardi1469561952.00Italy
677.30SpyPeter R. Hunt1531401451969.00Great Britain
686.00SpyGuy Hamilton1551221071974.00Great Britain
696.60SpyLewis Gilbert1581161171967.00Great Britain
707.00SpyTerence Young1591321301965.00Great Britain
716.10SpyGuy Hamilton1621221161971.00Great Britain
724.00SpyMaurice Labro16310511964.00France
733.90ThrillerLouis King1647551954.00United States
743.20SpyEnrico Bomba1679041965.00Italy
753.80SpyHenry Bay1689051966.00Italy
764.70SpyDavid Greene1697371972.00Great Britain
774.00SpyRobert Vernay1719711966.00France
784.50SpyClaudio Guzman17210821980.00United States
796.90ComedyCharles Chaplin17342131916.00United States
805.30ComedyAnthony Harvey174102101984.00United States
814.00AdventureGerardo Herrero1758811988.00Spain
824.90ThrillerRiccardo Freda1768861957.00Italy
833.50CrimeAndy Sidaris1789651987.00United States
845.00WesternR. G. Springsteen1799121967.00United States
852.50AdventureIvan Tors1809121964.00United States
864.50WesternJürgen Roland1818621964.00Germany
876.10DramaNorman Jewison18398431985.00United States
883.50FantasyAaron Lipstadt1857821985.00United States
895.40DramaCarlo Lizzani1869591953.00Italy
906.30ComedyMario Mattòli1877031939.00Italy
916.00MusicalClemente Fracassi1889771953.00Italy
925.30AdventureRoger Spottiswoode189106561990.00United States
934.70ActionJerry Jameson193110361977.00United States
944.70ComedyFrancis Schaeffer19410081991.00United States
954.00ComedyBurt Brickerhoff1966011989.00United States
964.40ComedyLuigi Filippo D'Amico1989961961.00Italy
975.10ComedyFrancesco Massaro1991001031983.00Italy
984.30ThrillerAlessandro Lucidi2009061992.00Italy
996.50GangsterRichard Wilson201104111959.00United States
1006.30DramaDaniel Taradash2028791956.00United States
Rows: 1-100 of 53397 | Columns: 12
In [52]:
# Retrieving the second actor
filmtv_movies.regexp(column = "actors", 
                     pattern = "[^,]+", 
                     method = "substr",
                     occurrence = 2,
                     name = "actor2").select(["actors", 
                                              "actor2"])
Abc
Varchar(2218)
Abc
actor2
Varchar(2218)
1 Steve Guttenberg
2 Irene Papas
3 Mary Arden
4 Ennio Girolami
5 Stéphane Freiss
6 Patrick Bergin
7 Lenny Von Dohlen
8 Monica Vitti
9 Lambert Wilson
10 Judit Pogàny
11 Sandrine Bonnaire
12 Dan O'Herlihy
13 Mark Huston
14 Ira Fürstenberg
15 Keith Gordon
16 Gerald Okamura
17 Morgan Freeman
18 Lisa Blount
19 Anjanette Comer
20 Luciana Paluzzi
21 Massimiliano Pazzaglia
22 Howie Mandel
23 Nino Besozzi
24 Jason Bateman
25 Jacqueline Bisset
26 Gena Rowlands
27 Ruth Gordon
28 Germana Paolieri
29 Karl Ludwig Diehl
30 Trax Colton
31 Joseph Cotten
32 Perry Lang
33 Lisa Hartman
34 Marvin Sither
35 Andreina Pagnani
36 Mariella Lotti
37 Craig T. Nelson
38 Ittoku Kishibe
39 Judy Bowker
40 Dean Martin
41 Isa Barzizza
42 Jean Simmons
43 Helen Hayes
44 Margaret Colin
45 Adriano Rimoldi
46 Walter Brennan
47 Virgina McKenna
48 Greer Garson
49 Jean Kent
50 Tamara Lees
51 Robert Ryan
52 Brigitte Bardot
53 Nastassja Kinski
54 Paulette Dubost
55 Elliott Gould
56 June Havoc
57 Nino Manfredi
58 Luigi Giuliani
59 Hardy Krüger
60 Lily Tomlin
61 Andy Garcia
62 Frederic Forrest
63 Jack Lemmon
64 Nancy Everhard
65 Ursula Andress
66 Stephen Barclay
67 Diana Rigg
68 Christopher Lee
69 Akiko Wakabayashi
70 Claudine Auger
71 Jill St. John
72 Virna Lisi
73 Piper Laurie
74 Hélène Chanel
75 Mary Young
76 Robert Wagner
77 Christiane Minazzoli
78 Maud Adams
79 Albert Austin
80 Nick Nolte
81 Conrado Sanmartin
82 Geneviève Page
83 Hope Marie Carlton
84 Yvonne De Carlo
85 Robert Culp
86 Tony Kendall
87 Anne Bancroft
88 John Stockwell
89 Marina Berti
90 Vittorio De Sica
91 Lois Maxwell
92 Robert Downey jr.
93 James Stewart
94 Carol Kane
95 Ted Lange
96 Pierre Brice
97 Jerry Calà
98 Daniela Poggi
99 Rod Steiger
100 Brian Keith
Out[52]:
Rows: 1-100 of 53397 | Columns: 2
In [53]:
# Computing the Number of actors
filmtv_movies.regexp(column = "actors", 
                     pattern = ",", 
                     method = "count",
                     name = "nb_actors")
filmtv_movies["nb_actors"].add(1)
filmtv_movies.select(["actors", "nb_actors"])
Abc
Varchar(2218)
123
nb_actors
Int
19
28
38
47
57
69
78
85
96
105
117
128
138
148
1510
168
175
186
198
208
212
228
238
246
258
267
279
288
298
307
317
327
338
347
357
368
378
388
397
408
413
428
438
447
457
467
477
488
497
507
518
527
537
547
554
568
577
589
598
609
618
628
638
648
657
668
674
684
694
704
715
723
734
744
753
764
774
784
793
804
814
824
833
843
853
865
875
883
893
902
914
924
935
944
953
963
975
983
995
1005
Out[53]:
Rows: 1-100 of 53397 | Columns: 2

See Also

vDataFrame.eval Evaluates a customized expression.