|
109 | 109 | versionadded_to_excel='',
|
110 | 110 | versionadded_melt='\n.. versionadded:: 0.20.0\n',
|
111 | 111 | other_melt='melt',
|
112 |
| - versionadded_crosstab = '\n.. versionadded:: 0.20.0\n', |
113 |
| - other_crosstab = 'crosstab') |
| 112 | + versionadded_crosstab='\n.. versionadded:: 0.20.0\n', |
| 113 | + other_crosstab='crosstab', |
| 114 | + versionadded_pivot_table='\n.. versionadded:: 0.20.0\n', |
| 115 | + other_pivot_table='pivot_table') |
114 | 116 |
|
115 | 117 | _numeric_only_doc = """numeric_only : boolean, default None
|
116 | 118 | Include only float, int, boolean data. If None, will attempt to use
|
@@ -3935,6 +3937,85 @@ def pivot(self, index=None, columns=None, values=None):
|
3935 | 3937 | from pandas.core.reshape import pivot
|
3936 | 3938 | return pivot(self, index=index, columns=columns, values=values)
|
3937 | 3939 |
|
| 3940 | + _shared_docs['pivot_table'] = """ |
| 3941 | + Create a spreadsheet-style pivot table as a DataFrame. The levels in the |
| 3942 | + pivot table will be stored in MultiIndex objects (hierarchical indexes) on |
| 3943 | + the index and columns of the result DataFrame |
| 3944 | +
|
| 3945 | + %(versionadded_pivot_table)s |
| 3946 | +
|
| 3947 | + Parameters |
| 3948 | + ---------- |
| 3949 | + data : DataFrame |
| 3950 | + values : column to aggregate, optional |
| 3951 | + index : column, Grouper, array, or list of the previous |
| 3952 | + If an array is passed, it must be the same length as the data. The list |
| 3953 | + can contain any of the other types (except list). |
| 3954 | + Keys to group by on the pivot table index. If an array is passed, it |
| 3955 | + is being used as the same manner as column values. |
| 3956 | + columns : column, Grouper, array, or list of the previous |
| 3957 | + If an array is passed, it must be the same length as the data. The list |
| 3958 | + can contain any of the other types (except list). |
| 3959 | + Keys to group by on the pivot table column. If an array is passed, it |
| 3960 | + is being used as the same manner as column values. |
| 3961 | + aggfunc : function or list of functions, default numpy.mean |
| 3962 | + If list of functions passed, the resulting pivot table will have |
| 3963 | + hierarchical columns whose top level are the function names (inferred |
| 3964 | + from the function objects themselves) |
| 3965 | + fill_value : scalar, default None |
| 3966 | + Value to replace missing values with |
| 3967 | + margins : boolean, default False |
| 3968 | + Add all row / columns (e.g. for subtotal / grand totals) |
| 3969 | + dropna : boolean, default True |
| 3970 | + Do not include columns whose entries are all NaN |
| 3971 | + margins_name : string, default 'All' |
| 3972 | + Name of the row / column that will contain the totals |
| 3973 | + when margins is True. |
| 3974 | +
|
| 3975 | + Examples |
| 3976 | + -------- |
| 3977 | + >>> df |
| 3978 | + A B C D |
| 3979 | + 0 foo one small 1 |
| 3980 | + 1 foo one large 2 |
| 3981 | + 2 foo one large 2 |
| 3982 | + 3 foo two small 3 |
| 3983 | + 4 foo two small 3 |
| 3984 | + 5 bar one large 4 |
| 3985 | + 6 bar one small 5 |
| 3986 | + 7 bar two small 6 |
| 3987 | + 8 bar two large 7 |
| 3988 | +
|
| 3989 | + >>> table = pivot_table(df, values='D', index=['A', 'B'], |
| 3990 | + ... columns=['C'], aggfunc=np.sum) |
| 3991 | + >>> table |
| 3992 | + small large |
| 3993 | + foo one 1 4 |
| 3994 | + two 6 NaN |
| 3995 | + bar one 5 4 |
| 3996 | + two 6 7 |
| 3997 | +
|
| 3998 | + Returns |
| 3999 | + ------- |
| 4000 | + table : DataFrame |
| 4001 | +
|
| 4002 | + See also |
| 4003 | + -------- |
| 4004 | + DataFrame.pivot : pivot without aggregation that can handle |
| 4005 | + non-numeric data |
| 4006 | + %(other_pivot_table)s |
| 4007 | + """ |
| 4008 | + |
| 4009 | + @Appender(_shared_docs['pivot_table'] % _shared_doc_kwargs) |
| 4010 | + def pivot_table(self, values=None, index=None, columns=None, |
| 4011 | + aggfunc='mean', fill_value=None, margins=False, |
| 4012 | + dropna=True, margins_name='All'): |
| 4013 | + from pandas.tools.pivot import pivot_table |
| 4014 | + return pivot_table(self, values=values, index=index, columns=columns, |
| 4015 | + aggfunc=aggfunc, fill_value=fill_value, |
| 4016 | + margins=margins, dropna=dropna, |
| 4017 | + margins_name=margins_name) |
| 4018 | + |
3938 | 4019 | def stack(self, level=-1, dropna=True):
|
3939 | 4020 | """
|
3940 | 4021 | Pivot a level of the (possibly hierarchical) column labels, returning a
|
|
0 commit comments