Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pandas/tools/pivot.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def _convert_by(by):


def crosstab(index, columns, values=None, rownames=None, colnames=None,
aggfunc=None, margins=False, dropna=True, normalize=False):
aggfunc=None, margins=False, dropna=True, normalize=False,
margins_name='All'):
"""
Compute a simple cross-tabulation of two (or more) factors. By default
computes a frequency table of the factors unless an array of values and an
Expand Down Expand Up @@ -420,6 +421,9 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None,
- If margins is `True`, will also normalize margin values.

.. versionadded:: 0.18.1
margins_name : string, default 'All'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a ..versionadded:: 0.20.0 for this parameter?

Name of the row / column that will contain the totals
when margins is True.


Notes
Expand Down Expand Up @@ -488,14 +492,16 @@ def crosstab(index, columns, values=None, rownames=None, colnames=None,
df = DataFrame(data)
df['__dummy__'] = 0
table = df.pivot_table('__dummy__', index=rownames, columns=colnames,
aggfunc=len, margins=margins, dropna=dropna)
aggfunc=len, margins=margins, dropna=dropna,
margins_name=margins_name)
table = table.fillna(0).astype(np.int64)

else:
data['__dummy__'] = values
df = DataFrame(data)
table = df.pivot_table('__dummy__', index=rownames, columns=colnames,
aggfunc=aggfunc, margins=margins, dropna=dropna)
aggfunc=aggfunc, margins=margins, dropna=dropna,
margins_name=margins_name)

# Post-process
if normalize is not False:
Expand Down