vDataFrame.narrow

In [ ]:
vDataFrame.narrow(index, 
                  columns: list = [],
                  col_name: str = "column", 
                  val_name: str = "value")

Returns the narrow table of the vDataFrame using the input vcolumns.

Parameters

Name Type Optional Description
index
str / list
Index(es) used to identify the Row.
columns
list
List of the names of the vcolumns. If empty, all the vcolumns except the index(es) will be used.
col_name
str
Alias of the vcolumn representing the different input vcolumns names as categories.
val_name
str
Alias of the vcolumn representing the different input vcolumns values.

Returns

vDataFrame : the narrow table object.

Example

In [1]:
from verticapy.datasets import load_amazon
amazon = load_amazon()
display(amazon)
123
number
Int
📅
date
Date
Abc
state
Varchar(32)
101998-01-01Acre
201998-01-01Alagoas
301998-01-01Amapa
401998-01-01Amazonas
501998-01-01Bahia
601998-01-01Ceara
701998-01-01Distrito Federal
801998-01-01Espirito Santo
901998-01-01Goias
1001998-01-01Maranhao
1101998-01-01Mato Grosso
1201998-01-01Mato Grosso
1301998-01-01Minas Gerais
1401998-01-01Para
1501998-01-01Paraiba
1601998-01-01Paraiba
1701998-01-01Pernambuco
1801998-01-01Piau
1901998-01-01Rio
2001998-01-01Rio
2101998-01-01Rio
2201998-01-01Rondonia
2301998-01-01Roraima
2401998-01-01Santa Catarina
2501998-01-01Sao Paulo
2601998-01-01Sergipe
2701998-01-01Tocantins
2801998-02-01Acre
2901998-02-01Alagoas
3001998-02-01Amapa
3101998-02-01Amazonas
3201998-02-01Bahia
3301998-02-01Ceara
3401998-02-01Distrito Federal
3501998-02-01Espirito Santo
3601998-02-01Goias
3701998-02-01Maranhao
3801998-02-01Mato Grosso
3901998-02-01Mato Grosso
4001998-02-01Minas Gerais
4101998-02-01Para
4201998-02-01Paraiba
4301998-02-01Paraiba
4401998-02-01Pernambuco
4501998-02-01Piau
4601998-02-01Rio
4701998-02-01Rio
4801998-02-01Rio
4901998-02-01Rondonia
5001998-02-01Roraima
5101998-02-01Santa Catarina
5201998-02-01Sao Paulo
5301998-02-01Sergipe
5401998-02-01Tocantins
5501998-03-01Acre
5601998-03-01Alagoas
5701998-03-01Amapa
5801998-03-01Amazonas
5901998-03-01Bahia
6001998-03-01Ceara
6101998-03-01Distrito Federal
6201998-03-01Espirito Santo
6301998-03-01Goias
6401998-03-01Maranhao
6501998-03-01Mato Grosso
6601998-03-01Mato Grosso
6701998-03-01Minas Gerais
6801998-03-01Para
6901998-03-01Paraiba
7001998-03-01Paraiba
7101998-03-01Pernambuco
7201998-03-01Piau
7301998-03-01Rio
7401998-03-01Rio
7501998-03-01Rio
7601998-03-01Rondonia
7701998-03-01Roraima
7801998-03-01Santa Catarina
7901998-03-01Sao Paulo
8001998-03-01Sergipe
8101998-03-01Tocantins
8201998-04-01Acre
8301998-04-01Alagoas
8401998-04-01Amapa
8501998-04-01Amazonas
8601998-04-01Bahia
8701998-04-01Ceara
8801998-04-01Distrito Federal
8901998-04-01Espirito Santo
9001998-04-01Goias
9101998-04-01Maranhao
9201998-04-01Mato Grosso
9301998-04-01Mato Grosso
9401998-04-01Minas Gerais
9501998-04-01Para
9601998-04-01Paraiba
9701998-04-01Paraiba
9801998-04-01Pernambuco
9901998-04-01Piau
10001998-04-01Rio
Rows: 1-100 of 6454 | Columns: 3
In [2]:
# Getting the Pivot
amazon_pivot = amazon.pivot(index = "date",
                            columns = "state",
                            values = "number",
                            aggr = "sum")
display(amazon_pivot)
📅
date
Date
123
Acre
Int
123
Alagoas
Int
123
Amapa
Int
123
Amazonas
Int
123
Bahia
Int
123
Ceara
Int
123
Distrito Federal
Int
123
Espirito Santo
Int
123
Goias
Int
123
Maranhao
Int
123
Mato Grosso
Int
123
Minas Gerais
Int
123
Para
Int
123
Paraiba
Int
123
Pernambuco
Int
123
Piau
Int
123
Rio
Int
123
Rondonia
Int
123
Roraima
Int
123
Santa Catarina
Int
123
Sao Paulo
Int
123
Sergipe
Int
123
Tocantins
Int
12002-10-016873055769554141606191131367518211548478851895926382757463355419142733201537
22014-01-0105410461321150118019551213325116199791221235558992089
32008-06-0100077210455235427484817033201102250282
42008-07-0141001082713125193502123319497187097391380461260441
52003-01-01101503115843926404144361078379001791888617162547455919835
62014-04-01716025183421513878988161274610638715162341037187
72008-09-011666983998483717754781255276195852552629443492147224637261723348602390
82014-05-011101222449182101481003224701104138852858421811618
92008-10-016521839563276918166100123134986758378766531582741830230148278568702832
102003-04-011202113763022877910292151413072243102681201064864
112003-05-01610210600157601016753115113192108469296
122014-08-01110031838526741559947125555927479195285556762322651388303812459145802917
132009-01-0101044917734714302407567424115025679178174521126043
142003-08-011976214186710391093611890220231208519556255191026864170770602151393401339
151998-01-0100000000000000000000000
162014-11-01561448467634882902018138691208398776717911171722820214343569451
172009-04-010501400081114460268813814731155767195
182014-12-01624354293144643028682400550155482814010134610314427745579223
192009-05-013023340971041914431287117012214621933142091
202003-11-011517750169533332704916849292477399619510415601248492526273471552146
211998-04-0100000000000000000000000
222015-02-01246110714325060539569084108735538922241823694065
232003-12-0114341114771024360181292424177522547874592294593862141571295836109
241998-05-0100000000000000000000000
252015-03-0123224622920025765389580616233351341516337684985
262009-08-0119402013214392637176471766306668538598481079011494842975928901124
272004-02-0137292122505112244129204582065122592941107
281998-08-01130113218159348382218117615634875681545127113422540058103747
292015-06-014023332422211827788717012002652013283106119310414731150
302009-11-01335510199734021653018895102724610012518486133620312831261839251
312004-04-0126048921032445384823715101041418259361352
322015-07-0110905356306251530347164219042889061401369013742354514901217
332009-12-0115512310230819870323917682581082832300351570237929020372146
342004-05-01730012439015714524387944102806922605350
351998-11-0101913164957504472237488321861189141424753121488121
362015-09-012928719258827956214762282296642312550308811068647116582834361297715636815510
372010-02-010260812066341586935881551026133541089470151523332
381998-12-017328419682276051313991762110081335911962533162612189
392015-10-0190540827249449896582130718076746699737087781279194406829525981812121364844
402010-03-010702116156400365827541091103859475411417911144120
412004-08-01645291207143061108121498188915011164212812125541100249268931872879401776
421999-02-010201431571621033469711228524132246120247251
431999-03-01052278330081171181374127447898778181
442016-01-01122419770285100143524125016113221312494929317545385942
452010-06-01100919232132784941174139945812081244011430767
462004-11-01102894920917362900042291639826139149842719465179837445213527914441424
472010-07-011262264051944855941232340317071432203716969674713160002408
482004-12-017717775342331580956325513271255508502373788392208160681026696
492016-03-01095140281411071361131228123816445347251081218226165
501999-06-01002764163625032232813237327472110305220113
512010-09-012531563278153233571965350759795198715059108130717953926534893181981677010172
522005-02-01031161432501845610927985923326824210546781927
531999-07-01100111078349311258522331898295212331135426840373
542010-10-012921626588952645026321227322850622048384338034738632411307647626012272
552005-03-01335012158503369520107219745131751724492732813
562016-06-018752904164542492897091537263502242415330217077919711148
571999-09-012093421612751241264189817391469826864419892648722463062310191103415
582016-07-0153331113734512479428372096418210041579526177541009969048068702737
591999-10-01604254791307309823743320881621363502650018014381261884101676301378
602011-01-01041053101322339124300611084649395812259753614
612005-06-0127027821163818952927332463041143171661535582360669
622016-09-0135861814231191819370581281703316611363209339531502171139486742081964449023245
632005-07-01368006762691424936311525031467436415514456979829028401082
642016-10-01509747932105141513109585225351394994852814973192598252184410156177102032
652000-01-0101127311051019370243049351270181436115
662011-04-01217051491137137368661040221653810855212106
672005-09-014253797281240661852381341629222421204790323991543136272139727211623125319
682011-05-01302618903213673628151169717737544161360354
692005-10-0154717335545840513781862171764728412654650833124083263367255988197221112913
702000-03-01113206965901468324181571414629125462664
712017-01-010762651549111353187837106219785285714410846283161
722011-08-014254161243179553619316132138318027422195447271958376116139175106711668
732006-01-01429620225211013852211006109403161148133151167041763691
742000-06-011006178161922294451513559554182254026060278
752017-04-011732094617609166569457892569195126418164
762000-07-0110039202181516332233149834542698075331170217700500
772017-05-01101140121961013514291712511450133660312936431576
782011-11-0174232823991761561165922611548153304349735282528124512179874144
792006-04-010205601012292125024921690201306394
802000-09-0126522191892285127314129313656761108025693901301099602438123658202552
812011-12-01450360121230144101391629100843321825736436219737249245336105
822006-05-01800443030335368620901028703388035
832000-10-01181342145335087518889052654671919544313783411255863644255564731053
842017-08-0114931336316101812114730149238757717214211962990201572100442873571398103536
852012-02-010415252004102537463051236355643163913013813445
862006-08-01839111142299550402958813827347959757584789117343124472857201277
872001-01-01050324110129291411834437291401011126219
882017-11-019810858552174812031172300946136907939366449269372327152371434
892012-04-011182339624748997618180115146119571225408240226
902012-05-01321212326190201032869691445996363341442218608217467
912006-11-0118122075923910120091200411145928832753857401762532645435108
922001-04-010001262024924176004321150380161019
932006-12-010307423169116100710524132141720220733911641017131715
942001-05-010200858108852113058373053664592211348
952012-08-0173901930111835278551291210395914690169645352736145052209439843504280
962007-02-01528092113303131332471233921114887961496228
972007-03-0127061412194952613155655431422066523152299
982001-08-0139611250197921925307872037102468589043376271133220213242459502242
992012-11-01139596968216899507572010490220615627218144715617418772506179
1002012-12-011594228047763101893129668618918121161083341315078326418128
Rows: 1-100 of 239 | Columns: 24
In [4]:
# Getting the Narrow
amazon_pivot.narrow("date",
                    col_name = "state",
                    val_name = "number")
📅
date
Date
Abc
state
Varchar(16)
123
number
Int
12002-10-01Acre687
22011-03-01Acre0
32005-08-01Acre4198
42014-01-01Acre0
52000-01-01Acre0
62008-06-01Acre0
72016-11-01Acre46
82002-11-01Acre86
92011-04-01Acre2
102005-09-01Acre4253
112014-02-01Acre0
122000-02-01Acre0
132008-07-01Acre41
142016-12-01Acre6
152002-12-01Acre1
162011-05-01Acre3
172005-10-01Acre547
182014-03-01Acre1
192000-03-01Acre11
202008-08-01Acre445
212017-01-01Acre0
222003-01-01Acre10
232011-06-01Acre10
242005-11-01Acre14
252014-04-01Acre7
262000-04-01Acre1
272008-09-01Acre1666
282017-02-01Acre1
292003-02-01Acre0
302005-12-01Acre2
312014-05-01Acre1
322000-05-01Acre1
332008-10-01Acre652
342017-03-01Acre0
352003-03-01Acre0
362011-08-01Acre425
372006-01-01Acre4
382014-06-01Acre17
392000-06-01Acre1
402008-11-01Acre4
412017-04-01Acre1
422003-04-01Acre1
432011-09-01Acre1204
442006-02-01Acre0
452000-07-01Acre1
462008-12-01Acre0
472017-05-01Acre10
482010-07-01Acre126
492003-05-01Acre6
502011-10-01Acre97
512006-03-01Acre0
522014-08-01Acre1100
532000-08-01Acre136
542009-01-01Acre0
552017-06-01Acre45
562003-06-01Acre0
572011-11-01Acre74
582006-04-01Acre0
592014-09-01Acre2175
602000-09-01Acre265
612009-02-01Acre2
622003-07-01Acre168
632011-12-01Acre4
642006-05-01Acre8
652014-10-01Acre406
662000-10-01Acre18
672009-03-01Acre1
682017-08-01Acre1493
692003-08-01Acre1976
702012-01-01Acre0
711998-01-01Acre0
722006-06-01Acre1
732013-07-01Acre54
742014-11-01Acre56
752009-07-01Acre31
762000-11-01Acre0
772009-04-01Acre0
782017-09-01Acre3429
792003-09-01Acre3942
802012-02-01Acre0
811998-02-01Acre0
822014-12-01Acre6
832000-12-01Acre0
842009-05-01Acre3
852017-10-01Acre1508
862003-10-01Acre740
872012-03-01Acre1
881998-03-01Acre0
892006-08-01Acre839
902015-01-01Acre1
912001-01-01Acre0
922009-06-01Acre0
932017-11-01Acre98
942003-11-01Acre15
952012-04-01Acre1
961998-04-01Acre0
972006-09-01Acre2370
982015-02-01Acre2
992001-02-01Acre0
1002003-12-01Acre1
Out[4]:
Rows: 1-100 of 5497 | Columns: 3

See Also

vDataFrame.pivot Returns the Pivot Table of the vDataFrame.