@@ -386,7 +386,8 @@ def _convert_by(by):
386
386
387
387
388
388
def crosstab (index , columns , values = None , rownames = None , colnames = None ,
389
- aggfunc = None , margins = False , dropna = True , normalize = False ):
389
+ aggfunc = None , margins = False , dropna = True , normalize = False ,
390
+ margins_name = 'All' ):
390
391
"""
391
392
Compute a simple cross-tabulation of two (or more) factors. By default
392
393
computes a frequency table of the factors unless an array of values and an
@@ -420,6 +421,9 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None,
420
421
- If margins is `True`, will also normalize margin values.
421
422
422
423
.. versionadded:: 0.18.1
424
+ margins_name : string, default 'All'
425
+ Name of the row / column that will contain the totals
426
+ when margins is True.
423
427
424
428
425
429
Notes
@@ -488,14 +492,16 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None,
488
492
df = DataFrame (data )
489
493
df ['__dummy__' ] = 0
490
494
table = df .pivot_table ('__dummy__' , index = rownames , columns = colnames ,
491
- aggfunc = len , margins = margins , dropna = dropna )
495
+ aggfunc = len , margins = margins , dropna = dropna ,
496
+ margins_name = margins_name )
492
497
table = table .fillna (0 ).astype (np .int64 )
493
498
494
499
else :
495
500
data ['__dummy__' ] = values
496
501
df = DataFrame (data )
497
502
table = df .pivot_table ('__dummy__' , index = rownames , columns = colnames ,
498
- aggfunc = aggfunc , margins = margins , dropna = dropna )
503
+ aggfunc = aggfunc , margins = margins , dropna = dropna ,
504
+ margins_name = margins_name )
499
505
500
506
# Post-process
501
507
if normalize is not False :
0 commit comments