+
    xȇi                    <   ^ RI Ht ^ RIt^ RIHtHtHt ^ RIt^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHtHtHt ^ RIHt ^ R	IHtHt ^ RIHu Ht ^ R
IHt ^ RIHtH t H!t! ^ RI"H#t# ^ RI$H%t% ]'       d   ^ RI&H't'H(t( ^ RI)H*t*H+t+H,t,H-t-H.t. ^ RI/H0t0 ]! R4      R+R R ll4       t1R R lt2R,R R llt3R-R R llt4R.R R llt5R.R R llt6R t7]! R4      R]
Pp                  R ]
Pp                  /R! R" ll4       t9]! R4      R/R# R$ ll4       t:R-R% R& llt;R0R' R( llt<R) R* lt=R# )1    )annotationsN)TYPE_CHECKINGLiteralcast)lib)
set_module)maybe_downcast_to_dtype)is_list_likeis_nested_list_like	is_scalar)ExtensionDtype)ABCDataFrame	ABCSeries)Grouper)Index
MultiIndexget_objs_combined_axis)concat)Series)CallableHashable)AggFuncTypeAggFuncTypeBaseAggFuncTypeDict
IndexLabelSequenceNotStr	DataFramepandasc               8    V ^8  d   QhRRRRRRRRRR	R
RRRRR/# )   datar   aggfuncr   marginsbooldropnamargins_namer   observedsortreturn )formats   "i/Users/max/.openclaw/workspace/postharvest/venv/lib/python3.14/site-packages/pandas/core/reshape/pivot.py__annotate__r.   7   sd     b: b:
b:
 b: b: b: b: b: b: b:    c                   \        V4      p\        V4      p\        V\        4      '       dr   . p. pV FG  p\        V VVVVVVVVV	V
VR7      pVP	                  V4       VP	                  \        VRV4      4       KI  	  \        W^R7      pVP                  V RR7      # \        V VVVVVVVVV	V
V4      pVP                  V RR7      # )a  
Create a spreadsheet-style pivot table as a DataFrame.

The levels in the pivot table will be stored in MultiIndex objects
(hierarchical indexes) on the index and columns of the result DataFrame.

Parameters
----------
data : DataFrame
    Input pandas DataFrame object.
values : list-like or scalar, optional
    Column or columns to aggregate.
index : column, Grouper, array, or sequence of the previous
    Keys to group by on the pivot table index. If a list is passed,
    it can contain any of the other types (except list). If an array is
    passed, it must be the same length as the data and will be used in
    the same manner as column values.
columns : column, Grouper, array, or sequence of the previous
    Keys to group by on the pivot table column. If a list is passed,
    it can contain any of the other types (except list). If an array is
    passed, it must be the same length as the data and will be used in
    the same manner as column values.
aggfunc : function, list of functions, dict, default "mean"
    If a list of functions is passed, the resulting pivot table will have
    hierarchical columns whose top level are the function names
    (inferred from the function objects themselves).
    If a dict is passed, the key is column to aggregate and the value is
    function or list of functions. If ``margins=True``, aggfunc will be
    used to calculate the partial aggregates.
fill_value : scalar, default None
    Value to replace missing values with (in the resulting pivot table,
    after aggregation).
margins : bool, default False
    If ``margins=True``, special ``All`` columns and rows
    will be added with partial group aggregates across the categories
    on the rows and columns.
dropna : bool, default True
    Do not include columns whose entries are all NaN. If True,

    * rows with an NA value in any column will be omitted before computing margins,
    * index/column keys containing NA values will be dropped (see ``dropna``
      parameter in :meth:``DataFrame.groupby``).

margins_name : str, default 'All'
    Name of the row / column that will contain the totals
    when margins is True.
observed : bool, default False
    This only applies if any of the groupers are Categoricals.
    If True: only show observed values for categorical groupers.
    If False: show all values for categorical groupers.

    .. versionchanged:: 3.0.0

        The default value is now ``True``.

sort : bool, default True
    Specifies if the result should be sorted.

**kwargs : dict
    Optional keyword arguments to pass to ``aggfunc``.

    .. versionadded:: 3.0.0

Returns
-------
DataFrame
    An Excel style pivot table.

See Also
--------
DataFrame.pivot : Pivot without aggregation that can handle
    non-numeric data.
DataFrame.melt: Unpivot a DataFrame from wide to long format,
    optionally leaving identifiers set.
wide_to_long : Wide panel to long format. Less flexible but more
    user-friendly than melt.

Notes
-----
Reference :ref:`the user guide <reshaping.pivot>` for more examples.

Examples
--------
>>> df = pd.DataFrame(
...     {
...         "A": ["foo", "foo", "foo", "foo", "foo", "bar", "bar", "bar", "bar"],
...         "B": ["one", "one", "one", "two", "two", "one", "one", "two", "two"],
...         "C": [
...             "small",
...             "large",
...             "large",
...             "small",
...             "small",
...             "large",
...             "small",
...             "small",
...             "large",
...         ],
...         "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],
...         "E": [2, 4, 5, 5, 6, 6, 8, 9, 9],
...     }
... )
>>> df
     A    B      C  D  E
0  foo  one  small  1  2
1  foo  one  large  2  4
2  foo  one  large  2  5
3  foo  two  small  3  5
4  foo  two  small  3  6
5  bar  one  large  4  6
6  bar  one  small  5  8
7  bar  two  small  6  9
8  bar  two  large  7  9

This first example aggregates values by taking the sum.

>>> table = pd.pivot_table(
...     df, values="D", index=["A", "B"], columns=["C"], aggfunc="sum"
... )
>>> table
C        large  small
A   B
bar one    4.0    5.0
    two    7.0    6.0
foo one    4.0    1.0
    two    NaN    6.0

We can also fill missing values using the `fill_value` parameter.

>>> table = pd.pivot_table(
...     df, values="D", index=["A", "B"], columns=["C"], aggfunc="sum", fill_value=0
... )
>>> table
C        large  small
A   B
bar one      4      5
    two      7      6
foo one      4      1
    two      0      6

The next example aggregates by taking the mean across multiple columns.

>>> table = pd.pivot_table(
...     df, values=["D", "E"], index=["A", "C"], aggfunc={"D": "mean", "E": "mean"}
... )
>>> table
                D         E
A   C
bar large  5.500000  7.500000
    small  5.500000  8.500000
foo large  2.000000  4.500000
    small  2.333333  4.333333

We can also calculate multiple types of aggregations for any given
value column.

>>> table = pd.pivot_table(
...     df,
...     values=["D", "E"],
...     index=["A", "C"],
...     aggfunc={"D": "mean", "E": ["min", "max", "mean"]},
... )
>>> table
                  D   E
               mean max      mean  min
A   C
bar large  5.500000   9  7.500000    6
    small  5.500000   9  8.500000    8
foo large  2.000000   5  4.500000    4
    small  2.333333   6  4.333333    2
)valuesindexcolumns
fill_valuer#   r$   r&   r'   r(   r)   kwargs__name__)keysaxispivot_table)method)_convert_by
isinstancelist__internal_pivot_tableappendgetattrr   __finalize__)r"   r1   r2   r3   r#   r4   r$   r&   r'   r(   r)   r5   piecesr7   func_tabletables   &&&&&&&&&&&,     r-   r9   r9   6   s    t E'"G'4  "$D+%)!F MM&!KKj$78! $ vq1!!$}!=="E d=99r/   c               8    V ^8  d   QhRRRRRRRRRR	R
RRRRR/# )r!   r"   r   r#   z!AggFuncTypeBase | AggFuncTypeDictr$   r%   r&   r'   r   r(   r)   r*   r+   )r,   s   "r-   r.   r.     sd     @ @
@
 /@ @ @ @ @ @ @r/   c                	   W#,           pVRJpV'       d   \        V4      '       d   Rp\        V4      pMRpV.pV F  pW9  g   K  \        V4      h	  . pW,            F@  p\        V\        4      '       d   VP
                  p VV 9   d   VP                  V4       K@  KB  	  \        V4      \        V P                  4      8  d
   V V,          p M2V P                  pV F  p VP                  V4      pK  	  \        V4      pV P                  WWR7      pV'       d
   VV,          pVP                  ! V3/ VB pV'       dD   \        V\        4      '       d.   \        VP                  4      '       d   VP                  RR7      pTpVP                   P"                  ^8  d   V'       d   VP                   P$                  R\        V4       p. p\'        \        V4      \        V4      4       FO  pVP                   P$                  V,          pVe   VV9   d   VP                  V4       K>  VP                  V4       KQ  	  VP)                  VVR7      pV'       g   \        VP                   \*        4      '       dU   \*        P,                  ! VP                   P.                  VP                   P$                  R7      pVP1                  V^ VR	7      p\        VP                  \*        4      '       dU   \*        P,                  ! VP                  P.                  VP                  P$                  R7      pVP1                  V^VR	7      pV
RJ d)   \        V\        4      '       d   VP3                  ^R
7      pVe_   VP5                  V4      pV\        J dD   V	'       g<   \6        P8                  ! V4      '       d    VP;                  \<        P>                  4      pV'       dE   V'       d'   W PA                  4       PC                  ^R
7      ,          p \E        VV VVVVVVVVVR7      pV'       dD   X'       g<   VP                  P"                  ^8  d!   VP                  PG                  ^ 4      Vn	        \        V4      ^ 8X  d   \        V4      ^ 8  d   VPH                  p\        V\        4      '       d   V'       d   VP                  R^R7      pV#   \         d     EKw  i ; i  \        \        \        3 d     EK  i ; i)zD
Helper of :func:`pandas.pivot_table` for any non-list ``aggfunc``.
NTF)r(   r)   r&   all)howr4   names)r8   r4   r8   )rowscolsr#   r5   r(   r'   r4   r&   )rI   r8   )%r
   r=   KeyErrorr<   r   keyr?   	TypeErrorlenr3   drop
ValueErrorgroupbyaggr   r&   r2   nlevelsrL   rangeunstackr   from_productlevelsreindex
sort_indexfillnar   
is_integerastypenpint64notnarH   _add_margins	droplevelT)r"   r1   r2   r3   r#   r4   r$   r&   r'   r(   r)   r5   r7   values_passedvalues_multii	to_filterxrQ   groupedaggedrE   index_names
to_unstacknamems   &&&&&&&&&&&&              r-   r>   r>     s   " ?D$&ML&\F LXF A}qk!  	A!W%%EE9$$Q' 	  y>C--	?D CS) 
 fll4lMG &/KK*6*E*UL11c%--6H6H'E {{Q5 kk''#e*5
s5z3t9-A;;$$Q'D|t{2!!!$!!$' . jZ@ekk:..''(:(:%++BSBSTAMM!!
MCEemmZ00''(<(<EMMDWDWXAMM!!
MCEt|
5,77  a (Z(c>(s~~j/I/I LL*E

((a(01D%!
 \emm.C.Ca.G//2
5zQ3w<!+ %&&6Q/Lq   z84 s$   S SSSS32S3c          
     ,    V ^8  d   QhRRRRRRRRR	R/# )
r!   rE   zDataFrame | Seriesr"   r   r(   r%   r'   r   r&   r+   )r,   s   "r-   r.   r.     sA     _ __
_ _ _ _r/   c                   \        V\        4      '       g   \        R 4      hRV R2pV P                  P                   F-  pWP                  P                  V4      9   g   K$  \        V4      h	  \        WWVV4      pV P                  ^8X  dO   V P                  P                  R,           F-  pWP                  P                  V4      9   g   K$  \        V4      h	  \        V4      ^8  d#   V3R\        V4      ^,
          ,          ,           pMTpV'       g?   \        V \        4      '       d)   V P                  V P                  WV,          /4      4      # V'       d4   \        V VVVVVVVVV
4
      p\        V\        4      '       g   V# Vw  pppME\        V \        4      '       g   Q h\!        WW4WVWxV
4	      p\        V\        4      '       g   V# Vw  pppVP#                  VP                  V	R7      pV F:  p\        V\        4      '       d   VV,          VV&   K'  VV^ ,          ,          VV&   K<  	  ^ RIHp V! V\)        V.4      R7      P*                  pVP                  P                  p\-        VP.                  4       FY  p\        V\0        4      '       d   K  VP3                  V.4      P                  pVV,          P5                  \6        V3R7      VV&   K[  	  \9        VV.4      pVVP                  n        V# )	z&margins_name argument must be a stringzConflicting name "z" in margins:   NNrJ   r   )r3   )args )r<   strrU   r2   rL   get_level_values_compute_grand_marginndimr3   rS   r   _append_internal_constructor_generate_marginal_resultstupler   )_generate_marginal_results_without_valuesr]   r   r   r   rg   setdtypesr   select_dtypesapplyr	   r   )rE   r"   r1   rN   rO   r#   r5   r(   r'   r4   r&   msglevelgrand_marginrQ   marginal_result_setresultmargin_keys
row_marginkr   margin_dummy	row_namesdtypes   &&&&&&&&&&&             r-   re   re     s    lC((ABB|nL
9C"";;77>>S/! # )wULzzQ]]((,,E}}==eDD o% -
 4y1}oTQ 77j	22 %%,%?@A
 	
 
8
 -u55&&*='Z %....GWhf
 -u55&&*='Z##FNNz#JJa(OJqM(1.JqM	  !Zu>@@L""I V]]#e^,,##UG,44)$/55#5( 6 
T $ V\*+F"FLLMr/   c                    V ^8  d   QhRRRR/# )r!   r"   r   r'   r   r+   )r,   s   "r-   r.   r.     s     = =
=<D=r/   c                   V'       d   / pW,          P                  4        F  w  rg \        V\        4      '       d   \        Wr4      ! R/ VB WV&   K1  \        V\        4      '       dL   \        W&,          \        4      '       d   \        WrV,          4      ! R/ VB WV&   K  W&,          ! V3/ VB WV&   K  V! V3/ VB WV&   K  	  V# WB! V P                  3/ VB /#   \
         d     K  i ; i)Nr+   )itemsr<   ry   r@   dictrR   r2   )r"   r1   r#   r5   r'   r   r   vs   &&&&&   r-   r{   r{     s     L&&(DAgs++&-a&9&CF&CLO..!'*c22*1!QZ*@*J6*J*1*Q*A&*A&-a&:6&:LO ) gdjj;F;<<	  s$   )CAC C3CC'&C'c               (    V ^8  d   QhRRRRRRRR/# )r!   r"   r   r(   r%   r'   r   r&   r+   )r,   s   "r-   r.   r.     s8     ]+ ]+
]+ ]+ ]+ ]+r/   c
                  aa \        S4      ^ 8  Ed7   . p
. pVV3R lp\        V4      ^ 8  d   WV,           ,          P                  W7V	R7      P                  ! V3/ VB p^pV P                  P                  ^ VR7       FG  w  ppVP                  pV! V4      pW,          VV&   V
P	                  V4       VP	                  V4       KI  	  EMUVSR,          V,           ,          P                  SR,          WyR7      P                  ! V3/ VB P                  p^ pV P                  ^ VR7       F  w  pp\        S4      ^8  d
   V! V4      pMSpV
P	                  V4       W,          P                  4       P                  p\        VP                  \        4      '       d8   \        P                  ! V.. VP                  P                  ORNR7      Vn        M'\        V.VP                  P                  R7      Vn        V
P	                  V4       VP	                  V4       K  	  V
'       g   V # \        WR7      p\        V4      ^ 8X  d   V# MT pV P                  p\        S4      ^ 8  d   VSV,           ,          P                  SWyR7      P                  ! V3/ VB pVP                  4       p\         P"                  ! \        S4      .\%        \        S4      4      4      pV Uu. uF   pVP                  P                  V,          NK"  	  ppVP                  P'                  V4      Vn        M+VP)                  \*        P,                  VP                  R	7      pVVV3# u upi )
r   c                H   < V S3R\        S4      ^,
          ,          ,           # )rx   rw   rS   )rQ   rO   r'   s   &r-   _all_key,_generate_marginal_results.<locals>._all_key*  s     &#d)a-)@@@r/   r(   r&   )r   r(   :Nru   NNrK   rq   rM   r2   )rS   rV   rW   rg   r?   to_framer<   r2   r   from_tuplesrL   r   rq   r   r3   stack	itertoolschainrY   reorder_levels_constructor_slicedrb   nan)rE   r"   r1   rN   rO   r#   r5   r(   r'   r&   table_piecesr   r   margincat_axisrQ   pieceall_keytransformed_piecer   r   new_order_indicesrj   new_order_namess   &&&&f&&&f&              r-   r   r     s    4y1}	A t9q=F]#@( &( 
 H#ggooAoI
U"3-!'g##E*""7+ J T"X&'bHD( &( 	  H#mm!hmG
Ut9q=&smG*G##E*$*K$8$8$:$<$<!ekk:66.8.D.D 	8 1 1848/%+
 /4WIEKKDTDT.U%+ ##$56""7+% H( LL8Ft9>M  mm
4y1}WTHW<S$"$ 	
  %%'
 &OOSYKs4y9IJ>OP>O:++11!44>OP%++::?K
--bffFNN-K
;
** Qs   !&Mc          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r!   rE   r   r"   r(   r%   r'   r   r&   r+   )r,   s   "r-   r.   r.   x  s:     2+ 2+2+
2+ 2+ 2+ 2+r/   c	                \  aa \        S4      ^ 8  d   . p	VV3R lp
\        V4      ^ 8  dK   VP                  W&VR7      V,          P                  ! V3/ VB pV
! 4       pWV&   T pV	P                  V4       MRVP                  ^ WhR7      P                  ! V3/ VB pV
! 4       pWV&   T pV	P                  V4       V# T pV P                  p	\        S4      '       d-   VP                  SWhR7      S,          P                  ! V3/ VB pM%\        \        P                  VP                  R7      pWV3# )r   c                 j   < \        S 4      ^8X  d   S# S3R\        S 4      ^,
          ,          ,           # )ru   rw   r   )rO   r'   s   r-   r   ;_generate_marginal_results_without_values.<locals>._all_key  s.    4yA~## ?Uc$i!m%<<<r/   r   )r   r(   r&   r   )rS   rV   r   r?   r3   r   rb   r   )rE   r"   rN   rO   r#   r5   r(   r'   r&   r   r   r   r   r   r   s   &&&f&&&f&      r-   r   r   x  s.    4y1}	=
 t9q=\\$&\I$OUU!F jG#'NFw' \\H\LRR!F jG#'NFw'Mmm
4yy\\$\I$OUU


 BFF&..9

**r/   c                    V f   . p V # \        V 4      '       gB   \        V \        P                  \        \
        \        34      '       g   \        V 4      '       d   V .p V # \        V 4      p V # N)	r   r<   rb   ndarrayr   r   r   callabler=   )bys   &r-   r;   r;     s_    	z I 	"b2::uiABBB<<T I "XIr/   r2   r1   c          
     ,    V ^8  d   QhRRRRRRRRRR/# )	r!   r"   r   r3   r   r2   zIndexLabel | lib.NoDefaultr1   r*   r+   )r,   s   "r-   r.   r.     sC     W W
W W &	W
 'W Wr/   c                  \         P                  ! V4      p\        ;QJ d0    R V P                  P                   4       F  '       g   K   RM%	  RM!! R V P                  P                   4       4      '       d[   V P                  RR7      p V P                  P                   Uu. uF  qUe   TM\        P                  NK  	  upV P                  n        V\        P                  J d[   V\        P                  Jd   \         P                  ! V4      pM. pV\        P                  J pV P                  Wd,           VR7      pEMV\        P                  J d   \        V P                  \        4      '       dH   \        V P                  P                  4       U	u. uF  qP                  P                  V	4      NK  	  p
p	M^V P                  V P                  V P                  P                  R7      .p
M+\         P                  ! V4       Uu. uF  qV,          NK  	  p
pV Uu. uF  qV,          NK  	  ppV
P!                  V4       \        P"                  ! V
4      p\%        V4      '       dF   \        V\&        4      '       g0   V P)                  W,          P*                  V\-        RV4      R	7      pM#V P                  W,          P*                  VR
7      p\-        RVP/                  V4      4      pVP                  P                   Uu. uF  qU\        P                  Jd   TMRNK  	  upVP                  n        V# u upi u up	i u upi u upi u upi )a0  
Return reshaped DataFrame organized by given index / column values.

Reshape data (produce a "pivot" table) based on column values. Uses
unique values from specified `index` / `columns` to form axes of the
resulting DataFrame. This function does not support data
aggregation, multiple values will result in a MultiIndex in the
columns. See the :ref:`User Guide <reshaping>` for more on reshaping.

Parameters
----------
data : DataFrame
    Input pandas DataFrame object.
columns : Hashable or a sequence of the previous
    Column to use to make new frame's columns.
index : Hashable or a sequence of the previous, optional
    Column to use to make new frame's index. If not given, uses existing index.
values : Hashable or a sequence of the previous, optional
    Column(s) to use for populating new frame's values. If not
    specified, all remaining columns will be used and the result will
    have hierarchically indexed columns.

Returns
-------
DataFrame
    Returns reshaped DataFrame.

Raises
------
ValueError:
    When there are any `index`, `columns` combinations with multiple
    values. `DataFrame.pivot_table` when you need to aggregate.

See Also
--------
DataFrame.pivot_table : Generalization of pivot that can handle
    duplicate values for one index/column pair.
DataFrame.unstack : Pivot based on the index values instead of a
    column.
wide_to_long : Wide panel to long format. Less flexible but more
    user-friendly than melt.

Notes
-----
For finer-tuned control, see hierarchical indexing documentation along
with the related stack/unstack methods.

Reference :ref:`the user guide <reshaping.pivot>` for more examples.

Examples
--------
>>> df = pd.DataFrame(
...     {
...         "foo": ["one", "one", "one", "two", "two", "two"],
...         "bar": ["A", "B", "C", "A", "B", "C"],
...         "baz": [1, 2, 3, 4, 5, 6],
...         "zoo": ["x", "y", "z", "q", "w", "t"],
...     }
... )
>>> df
    foo   bar  baz  zoo
0   one   A    1    x
1   one   B    2    y
2   one   C    3    z
3   two   A    4    q
4   two   B    5    w
5   two   C    6    t

>>> df.pivot(index="foo", columns="bar", values="baz")
bar  A   B   C
foo
one  1   2   3
two  4   5   6

>>> df.pivot(index="foo", columns="bar")["baz"]
bar  A   B   C
foo
one  1   2   3
two  4   5   6

>>> df.pivot(index="foo", columns="bar", values=["baz", "zoo"])
      baz       zoo
bar   A  B  C   A  B  C
foo
one   1  2  3   x  y  z
two   4  5  6   q  w  t

You could also assign a list of column names or a list of index names.

>>> df = pd.DataFrame(
...     {
...         "lev1": [1, 1, 1, 2, 2, 2],
...         "lev2": [1, 1, 2, 1, 1, 2],
...         "lev3": [1, 2, 1, 2, 1, 2],
...         "lev4": [1, 2, 3, 4, 5, 6],
...         "values": [0, 1, 2, 3, 4, 5],
...     }
... )
>>> df
    lev1 lev2 lev3 lev4 values
0   1    1    1    1    0
1   1    1    2    2    1
2   1    2    1    3    2
3   2    1    2    4    3
4   2    1    1    5    4
5   2    2    2    6    5

>>> df.pivot(index="lev1", columns=["lev2", "lev3"], values="values")
lev2    1         2
lev3    1    2    1    2
lev1
1     0.0  1.0  2.0  NaN
2     4.0  3.0  NaN  5.0

>>> df.pivot(index=["lev1", "lev2"], columns=["lev3"], values="values")
      lev3    1    2
lev1  lev2
   1     1  0.0  1.0
         2  2.0  NaN
   2     1  4.0  3.0
         2  NaN  5.0

A ValueError is raised if there are any duplicates.

>>> df = pd.DataFrame(
...     {
...         "foo": ["one", "one", "two", "two"],
...         "bar": ["A", "A", "B", "C"],
...         "baz": [1, 2, 3, 4],
...     }
... )
>>> df
   foo bar  baz
0  one   A    1
1  one   A    2
2  two   B    3
3  two   C    4

Notice that the first two rows are the same for our `index`
and `columns` arguments.

>>> df.pivot(index="foo", columns="bar", values="baz")
Traceback (most recent call last):
   ...
ValueError: Index contains duplicate entries, cannot reshape
c              3  (   "   T F  qR J x  K
  	  R # 5ir   r+   ).0rq   s   & r-   	<genexpr>pivot.<locals>.<genexpr>Z  s     
5$4D4<$4s   TF)deepN)r?   r   r   )r2   r3   r   r   )comconvert_to_list_likeanyr2   rL   copyr   
no_default	set_indexr<   r   rY   rX   rz   r   rq   extendfrom_arraysr
   r   r~   _valuesr   rZ   )r"   r3   r2   r1   columns_listlikerq   rO   r?   indexedrj   
index_listidxcoldata_columns
multiindexr   s   &$$$            r-   pivotr     s   t //8
 s
5DJJ$4$4
5sss
5DJJ$4$4
555yyey$EIZZEUEU
EUT$D#..8EU



 &++E2DD#..( ..# ! 
 CNN"$**j11 =B$**BTBT<U<UqJJ//2<U  

 ,,TZZdjjoo,N
 03/G/G/NO/Ns))/NJO-=>-=cS		-=>,'++J7

65(A(A''$$ -v6 ( G ..t|/C/C:.VG
 +w/?@AFAGASASASCNN*4ASFLL Mo
. P>$s   #L8#L=MM Mc          
     ,    V ^8  d   QhRRRRRRRRRR	/# )
r!   r$   r%   r'   r   r&   	normalizez/bool | Literal[0, 1, 'all', 'index', 'columns']r*   r   r+   )r,   s   "r-   r.   r.     sE     S S S S S ?S Sr/   c
                   Vf   Ve   \        R4      hVe   Vf   \        R4      h\        V 4      '       g   V .p \        V4      '       g   V.pRp
W,            Uu. uF#  p\        V\        \        34      '       g   K!  VNK%  	  ppV'       d   \        VRRR7      p
\        WRR7      p\        WR	R7      p\        W44      w  pppp^ R
IH	p / \        \        WRR7      4      C\        \        VVRR7      4      CpV! VV
R7      pVf   ^ VR&   R\        R^ /pM	VVR&   RV/pVP                  ! RRVRVRVRVRVRV/VB pV	RJd   \        VWVR7      pVP                  V^ R7      pVP                  V^R7      pV# u upi )a!  
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 aggregation function are passed.

Parameters
----------
index : array-like, Series, or list of arrays/Series
    Values to group by in the rows.
columns : array-like, Series, or list of arrays/Series
    Values to group by in the columns.
values : array-like, optional
    Array of values to aggregate according to the factors.
    Requires `aggfunc` be specified.
rownames : sequence, default None
    If passed, must match number of row arrays passed.
colnames : sequence, default None
    If passed, must match number of column arrays passed.
aggfunc : function, optional
    If specified, requires `values` be specified as well.
margins : bool, default False
    Add row/column margins (subtotals).
margins_name : str, default 'All'
    Name of the row/column that will contain the totals
    when margins is True.
dropna : bool, default True
    Do not include columns whose entries are all NaN.
normalize : bool, {'all', 'index', 'columns'}, or {0,1}, default False
    Normalize by dividing all values by the sum of values.

    - If passed 'all' or `True`, will normalize over all values.
    - If passed 'index' will normalize over each row.
    - If passed 'columns' will normalize over each column.
    - If margins is `True`, will also normalize margin values.

Returns
-------
DataFrame
    Cross tabulation of the data.

See Also
--------
DataFrame.pivot : Reshape data based on column values.
pivot_table : Create a pivot table as a DataFrame.

Notes
-----
Any Series passed will have their name attributes used unless row or column
names for the cross-tabulation are specified.

Any input passed containing Categorical data will have **all** of its
categories included in the cross-tabulation, even if the actual data does
not contain any instances of a particular category.

In the event that there aren't overlapping indexes an empty DataFrame will
be returned.

Reference :ref:`the user guide <reshaping.crosstabulations>` for more examples.

Examples
--------
>>> a = np.array(
...     [
...         "foo",
...         "foo",
...         "foo",
...         "foo",
...         "bar",
...         "bar",
...         "bar",
...         "bar",
...         "foo",
...         "foo",
...         "foo",
...     ],
...     dtype=object,
... )
>>> b = np.array(
...     [
...         "one",
...         "one",
...         "one",
...         "two",
...         "one",
...         "one",
...         "one",
...         "two",
...         "two",
...         "two",
...         "one",
...     ],
...     dtype=object,
... )
>>> c = np.array(
...     [
...         "dull",
...         "dull",
...         "shiny",
...         "dull",
...         "dull",
...         "shiny",
...         "shiny",
...         "dull",
...         "shiny",
...         "shiny",
...         "shiny",
...     ],
...     dtype=object,
... )
>>> pd.crosstab(a, [b, c], rownames=["a"], colnames=["b", "c"])
b   one        two
c   dull shiny dull shiny
a
bar    1     2    1     0
foo    2     2    1     2

Here 'c' and 'f' are not represented in the data and will not be
shown in the output because dropna is True by default. Set
dropna=False to preserve categories with no data.

>>> foo = pd.Categorical(["a", "b"], categories=["a", "b", "c"])
>>> bar = pd.Categorical(["d", "e"], categories=["d", "e", "f"])
>>> pd.crosstab(foo, bar)
col_0  d  e
row_0
a      1  0
b      0  1
>>> pd.crosstab(foo, bar, dropna=False)
col_0  d  e  f
row_0
a      1  0  0
b      0  1  0
c      0  0  0
Nz&aggfunc cannot be used without values.z)values cannot be used without an aggfunc.TF)	intersectr)   row)prefixr   r   )strictr   	__dummy__r#   r4   r2   r3   r$   r'   r&   r(   )r   r$   r'   )r2   r8   )r3   r8   )r   )rU   r   r<   r   r   r   
_get_names_build_names_mapperr   r   r   ziprS   r9   
_normalizerename_axis)r2   r3   r1   rownamescolnamesr#   r$   r'   r&   r   
common_idxrl   	pass_objsrownames_mapperunique_rownamescolnames_mapperunique_colnamesr   r"   dfr5   rE   s   &&&&&&&&&&            r-   crosstabr     s   h ~'-ABBgoDEEu%%w'')J!OXOqz!i=V/WOIX+IER
%%8H'E:H 	H/ !
s?$7
8
s?GD9
:D 
4z	*B~;S,2 ;W% NN 		  	 		
 "	 	 	 	E Yl
 O!<EoA>ELi Ys   E<>E<c               (    V ^8  d   QhRRRRRRRR/# )r!   rE   r   r$   r%   r'   r   r*   r+   )r,   s   "r-   r.   r.   m  s2     M MM*.M>FMMr/   c                   \        V\        \        34      '       g   ^ R^R/p WA,          pVRJ d<   RR RR RR	 /pVR,          VR
&    Wa,          pT! T 4      p T P                  ^ 4      p T # VR
J Ed   V P                  pV P                  p	V P                  R,          P                  p
W:9  W:8g  ,          '       d   \	        V R24      hV P                  RR1R3,          pV P                  RRR13,          pV P                  RR1RR13,          p \        WRR7      p VR8X  d>   WP                  4       ,          p\        W.^R7      p V P                  ^ 4      p Wn        V # VR8X  dC   WP                  4       ,          pV P                  VR
R7      p V P                  ^ 4      p Wn        V # VR8X  g   VR
J d|   WP                  4       ,          pWP                  4       ,          p^VP                  V&   \        W.^R7      p V P                  VR
R7      p V P                  ^ 4      p Wn        Wn        V # \	        R4      h\	        R4      h  \         d   p\	        R4      ThRp?ii ; i  \         d   p\	        R4      ThRp?ii ; i)r   r2   r3   zNot a valid normalize argumentNFrH   c                R    W P                  ^R7      P                  ^ R7      ,          # ru   rM   sumrl   s   &r-   <lambda>_normalize.<locals>.<lambda>z  s    QA!2!2!2!::r/   c                .    W P                  4       ,          # r   r   r   s   &r-   r   r   {  s    UUWr/   c                H    V P                  V P                  ^R7      ^ R7      # r   )divr   r   s   &r-   r   r   |  s    quuQUUU]u;r/   Tz not in pivoted DataFrame)r   r$   rM   )ignore_indexzNot a valid margins argument)r   :NNN)r<   r%   ry   rP   rU   r_   r2   r3   ilocrq   r   r   r   r}   loc)rE   r   r$   r'   	axis_subserrnormalizersftable_indextable_columnslast_ind_or_colcolumn_marginindex_margins   &&&&         r-   r   r   m  s    i$--I.		H!,I % :,;3
 (.D	H&A %Qf Lc 
Dkk**U+00 /L4STT~-FGHH

3B37+zz"crc'* 

3B38$ 5uE 	!),=,=,??ME1:ELLOE)M2 L/ '!'*:*:*<<L**<d*KELLOE%K& L# %9#4),=,=,??M'*:*:*<<L-.L\*E1:E**<d*KELLOE%K)M L =>> 788I  	H=>CG	H  	H=>CG	Hs/   I	 
I( 	I%I  I%(J3I??Jc                    V ^8  d   QhRRRR/# )r!   r   ry   r*   r=   r+   )r,   s   "r-   r.   r.     s      C D r/   c                v   Vfp   . p\        V 4       F\  w  r4\        V\        4      '       d,   VP                  e   VP	                  VP                  4       KF  VP	                  V RV 24       K^  	  V# \        V4      \        V 4      8w  d   \        R4      h\        V\        4      '       g   \        V4      pV# )N_z*arrays and names must have the same length)	enumerater<   r   rq   r?   rS   AssertionErrorr=   )arrsrL   r   rj   arrs   &&&  r-   r   r     s    }oFA#y))chh.BSXX&xq_-	 & L u:T" !MNN%&&KELr/   c               $    V ^8  d   QhRRRRRR/# )r!   r   z	list[str]r   r*   z;tuple[dict[str, str], list[str], dict[str, str], list[str]]r+   )r,   s   "r-   r.   r.     s)     -N -N-N#,-N@-Nr/   c                   \        V 4      \        V4      ,          p\        V 4       UUu/ uF  w  r4WB9   g   K  RV 2VbK  	  ppp\        V 4       UUu. uF  w  r4WB9   d   RV 2MTNK  	  ppp\        V4       UUu/ uF  w  r4WB9   g   K  RV 2VbK  	  ppp\        V4       UUu. uF  w  r4WB9   d   RV 2MTNK  	  pppWVWx3# u uppi u uppi u uppi u uppi )aT  
Given the names of a DataFrame's rows and columns, returns a set of unique row
and column names and mappers that convert to original names.

A row or column name is replaced if it is duplicate among the rows of the inputs,
among the columns of the inputs or between the rows and the columns.

Parameters
----------
rownames: list[str]
colnames: list[str]

Returns
-------
Tuple(Dict[str, str], List[str], Dict[str, str], List[str])

rownames_mapper: dict[str, str]
    a dictionary with new row names as keys and original rownames as values
unique_rownames: list[str]
    a list of rownames with duplicate names replaced by dummy names
colnames_mapper: dict[str, str]
    a dictionary with new column names as keys and original column names as values
unique_colnames: list[str]
    a list of column names with duplicate names replaced by dummy names

row_col_)r   r  )	r   r   	dup_namesrj   rq   r   r   r   r   s	   &&       r-   r   r     s   : HH-I )2((;(;WQt?P$qc
D(;   BK8ATATgad'$qc
T1AT  
 )2((;(;WQt?P$qc
D(;   BK8ATATgad'$qc
T1AT   _MMs"   
C
CC=
C
C'C)
NNNmeanNFTAllTT)r  NT)r  )r  T)NNNNFr  TF)r   )>
__future__r   r   typingr   r   r   numpyrb   pandas._libsr   pandas.util._decoratorsr   pandas.core.dtypes.castr	   pandas.core.dtypes.commonr
   r   r   pandas.core.dtypes.dtypesr   pandas.core.dtypes.genericr   r   pandas.core.commoncorecommonr   pandas.core.groupbyr   pandas.core.indexes.apir   r   r   pandas.core.reshape.concatr   pandas.core.seriesr   collections.abcr   r   pandas._typingr   r   r   r   r   r   r   r9   r>   re   r{   r   r   r;   r   r   r   r   r   r   r+   r/   r-   <module>r      s   "     . ; 
 5
 !   ' 
 . %
  ! Hb: b:J@F_D=.]+@2+j HW ),	W
 *-W Wt HS SlM`"-Nr/   