ó
    Ñ]j›  ã                  ó
  • S SK Jr  S SKrS SKJrJrJr  S SKrS SK	J
r
  S SKJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJrJr  S SKJs  Jr  S S
KJr  S SKJrJ r J!r!  S SK"J#r#  S SK$J%r%  \(       a  S SK&J'r'J(r(  S SK)J*r*J+r+J,r,J-r-J.r.  S SK/J0r0  \" S5                S               S S jj5       r1                S!S jr2   S"         S#S jjr3 S$   S%S jjr4  S&       S'S jjr5  S&         S(S jjr6S r7\" S5      \
Rp                  \
Rp                  S.         S)S jj5       r9\" S5              S*         S+S jj5       r: S$       S,S jjr;S-S.S jjr<      S/S jr=g)0é    )Ú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                ót  • [        U5      n[        U5      n[        U[        5      (       ah  / n/ nU HD  n[        U UUUUUUUUU	U
US9nUR	                  U5        UR	                  [        USU5      5        MF     [        XÍSS9nUR                  U SS9$ [        U UUUUUUUUU	U
U5      nUR                  U SS9$ )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_valueÚaggfuncÚmarginsÚdropnaÚmargins_nameÚobservedÚsortÚkwargsÚ__name__é   )ÚkeysÚaxisÚpivot_table)Úmethod)Ú_convert_byÚ
isinstanceÚlistÚ__internal_pivot_tableÚappendÚgetattrr   Ú__finalize__)Údatar!   r"   r#   r%   r$   r&   r'   r(   r)   r*   r+   Úpiecesr.   ÚfuncÚ_tableÚtables                    ÚV/home/mande/repo/quber/.venv/lib/python3.13/site-packages/pandas/core/reshape/pivot.pyr0   r0   6   sõ   € ôt ˜Ó€EÜ˜'Ó"€Gä�'œ4× Ñ Ø"$ˆØˆÛˆDÜ+ØØØØØ%ØØØØ)Ø!ØØñˆFð �M‰M˜&Ô!Ø�K‰Kœ  j°$Ó7Ö8ñ! ô$ �v¨qÑ1ˆØ×!Ñ! $¨}Ð!Ð=Ð=ä"ØØØØØØØØØØØØó€Eð ×Ñ˜d¨=ÐÐ9Ð9ó    c                ó6	  • X#-   nUSLnU(       a¬  [        U5      (       a  Sn[        U5      nOSnU/nU H  nXð;  d  M
  [        U5      e   / nXÁ-    H>  n[        U[        5      (       a  UR
                  n UU ;   a  UR                  U5        M>  M@     [        U5      [        U R                  5      :  a  U U   n O2U R                  nU H  n UR                  U5      nM     [        U5      nU R                  XÉX§S9nU(       a  UU   nUR                  " U40 UD6nU(       a>  [        U[        5      (       a)  [        UR                  5      (       a  UR                  SS9nUnUR                   R"                  S:”  a¦  U(       aŸ  UR                   R$                  S[        U5       n/ n['        [        U5      [        U5      5       HI  nUR                   R$                  U   nUb  UU;   a  UR                  U5        M8  UR                  U5        MK     UR)                  UUS9nU(       dÚ  [        UR                   [*        5      (       aN  [*        R,                  " UR                   R.                  UR                   R$                  S	9nUR1                  US
US9n[        UR                  [*        5      (       aN  [*        R,                  " UR                  R.                  UR                  R$                  S	9nUR1                  USUS9nU
SL a$  [        U[        5      (       a  UR3                  SS9nUb[  UR5                  U5      nU[        L aA  U	(       d:  [6        R8                  " U5      (       a  UR;                  [<        R>                  5      nU(       a9  U(       a  X RA                  5       RC                  SS9   n [E        UU UUUUUUUUUS9nU(       aA  W(       d:  UR                  R"                  S:”  a   UR                  RG                  S
5      Ul	        [        U5      S
:X  a  [        U5      S
:”  a  URH                  n[        U[        5      (       a  U(       a  UR                  SSS9nU$ ! [         a     GM(  f = f! [        [        [        4 a     GMÍ  f = f)zD
Helper of :func:`pandas.pivot_table` for any non-list ``aggfunc``.
NTF)r)   r*   r'   Úall)Úhowr-   ©r$   ©Únamesr   )r/   r$   ©r/   )ÚrowsÚcolsr%   r+   r)   r(   r$   r'   )rB   r/   )%r
   r4   ÚKeyErrorr3   r   Úkeyr6   Ú	TypeErrorÚlenr#   ÚdropÚ
ValueErrorÚgroupbyÚaggr   r'   r"   ÚnlevelsrE   ÚrangeÚunstackr   Úfrom_productÚlevelsÚreindexÚ
sort_indexÚfillnar   Ú
is_integerÚastypeÚnpÚint64ÚnotnarA   Ú_add_marginsÚ	droplevelÚT)r9   r!   r"   r#   r%   r$   r&   r'   r(   r)   r*   r+   r.   Úvalues_passedÚvalues_multiÚiÚ	to_filterÚxrJ   ÚgroupedÚaggedr=   Úindex_namesÚ
to_unstackÚnameÚms                             r>   r5   r5     sè  € ð" ‰?€Dà $Ð&€MÞÜ˜×ÑØˆLÜ˜&“\‰Fà ˆLØ�XˆFó ˆAØ�}Ü˜q“kÐ!ñ ð ˆ	Ø”ˆAÜ˜!œW×%Ñ%Ø—E‘E�ðØ˜“9Ø×$Ñ$ QÖ'ñ ñ	 ô ˆy‹>œC §¡Ó-Ó-Ø˜	‘?ˆDøð —‘ˆÛˆCðØŸ™ SÓ)’ñ ô
 �f“ˆà�l‰l˜4¸ˆlÐM€GÞð ˜&‘/ˆà�KŠK˜Ñ* 6Ñ*€Eæ”*˜U¤L×1Ñ1´c¸%¿-¹-×6HÑ6HØ—‘ �Ð'ˆà€Eð ‡{�{×Ñ˜QÓ¦5ð —k‘k×'Ñ'¨¬#¨e«*Ð5ˆØˆ
Ü”s˜5“z¤3 t£9Ö-ˆAØ—;‘;×$Ñ$ QÑ'ˆDØ‰|˜t {Ó2Ø×!Ñ! !Ö$à×!Ñ! $Ö'ñ .ð —‘˜j°Z�Ð@ˆæÜ�e—k‘k¤:×.Ñ.Ü×'Ò'¨¯©×(:Ñ(:À%Ç+Á+×BSÑBSÑTˆAØ—M‘M !¨!¸
�MÐCˆEä�e—m‘m¤Z×0Ñ0Ü×'Ò'¨¯©×(<Ñ(<ÀEÇMÁM×DWÑDWÑXˆAØ—M‘M !¨!¸
�MÐCˆEàˆt‚|œ
 5¬,×7Ñ7Ø× Ñ  aÐ Ð(ˆàÑØ—‘˜ZÓ(ˆØ”cŠ>¦(¬s¯~ª~¸j×/IÑ/Ið —L‘L¤§¡Ó*ˆEæÞØŸ
™
›×(Ñ(¨aÐ(Ð0Ñ1ˆDÜØØØØØØØØØ%Ø!Øñ
ˆö ž\¨e¯m©m×.CÑ.CÀaÓ.GØŸ™×/Ñ/°Ó2ˆŒÜ
ˆ5ƒz�Qƒœ3˜w›<¨!Ó+Ø—‘ˆô �%œ×&Ñ&®6Ø—‘ ¨Q�Ð/ˆà€Løôq ó Ûðûô œz¬8Ð4ó Ûðús$   Á7Q,ÃQ>Ñ,
Q;Ñ:Q;Ñ>RÒRc                óˆ  • [        U[        5      (       d  [        S5      eSU S3nU R                  R                   H,  nX€R                  R                  U5      ;   d  M#  [        U5      e   [        XXVU5      nU R                  S:X  aI  U R                  R                  SS   H,  nX€R                  R                  U5      ;   d  M#  [        U5      e   [        U5      S:”  a  U4S[        U5      S-
  -  -   nOUnU(       d9  [        U [        5      (       a$  U R                  U R                  XíU   05      5      $ U(       a2  [        U UUUUUUUUU
5
      n[        U[        5      (       d  U$ Uu  nnnOC[        U [        5      (       d   e[!        XX4XVXxU
5	      n[        U[        5      (       d  U$ Uu  nnnUR#                  UR                  U	S9nU H-  n[        U[        5      (       a
  UU   UU'   M"  UUS      UU'   M/     SS	KJn  U" U[)        U/5      S
9R*                  nUR                  R                  n[-        UR.                  5       HQ  n[        U[0        5      (       a  M  UR3                  U/5      R                  nUU   R5                  [6        U4S9UU'   MS     [9        UU/5      nUUR                  l        U$ )Nz&margins_name argument must be a stringzConflicting name "z" in marginsé   r-   ©Ú rC   r   r   )r#   )Úargs)r3   ÚstrrN   r"   rE   Úget_level_valuesÚ_compute_grand_marginÚndimr#   rL   r   Ú_append_internalÚ_constructorÚ_generate_marginal_resultsÚtupler   Ú)_generate_marginal_results_without_valuesrV   r   r   r   r`   ÚsetÚdtypesr   Úselect_dtypesÚapplyr	   r   )r=   r9   r!   rG   rH   r%   r+   r)   r(   r$   r'   ÚmsgÚlevelÚgrand_marginrJ   Úmarginal_result_setÚresultÚmargin_keysÚ
row_marginÚkr   Úmargin_dummyÚ	row_namesÚdtypes                           r>   r^   r^   Ÿ  sµ  € ô �l¤C×(Ñ(ÜÐAÓBÐBà˜|˜n¨LÐ
9€CØ—‘×"Ô"ˆØŸ;™;×7Ñ7¸Ó>Õ>Ü˜S“/Ð!ñ #ô )¨°wÈÓU€Là‡z�z�Qƒà—]‘]×(Ñ(¨¨Ó,ˆEØŸ}™}×=Ñ=¸eÓDÕDÜ  “oÐ%ñ -ô
 ˆ4ƒy�1ƒ}Øˆo ¬¨T«°Q©Ñ 7Ñ7‰àˆæ”j ¬	×2Ñ2ð ×%Ñ%Ø×Ñ °,Ñ%?Ð@ÓAó
ð 	
ö 
Ü8ØØØØØØØØØØó
Ðô Ð-¬u×5Ñ5Ø&Ð&Ø*=Ñ'ˆ�™Zô ˜%¤×.Ñ.Ð.Ð.ÜGØ˜ W°hÈfó
Ðô Ð-¬u×5Ñ5Ø&Ð&Ø*=Ñ'ˆ�˜Zà×#Ñ# F§N¡N¸zÐ#ÐJ€JãˆÜ�aœ×ÑØ(¨™OˆJ�q‹Mà(¨¨1©Ñ.ˆJ�q‹Mñ	 õ !á˜Z´¸°u³Ñ>×@Ñ@€Là—‘×"Ñ"€Iô �V—]‘]Ö#ˆÜ�eœ^×,Ñ,áà×#Ñ# U GÓ,×4Ñ4ˆØ)¨$Ñ/×5Ñ5Ü#¨5¨(ð 6ð 
ˆ�TÓñ $ô �V˜\Ð*Ó+€FØ"€F‡L�LÔà€Mr?   c                óª  • U(       a¨  0 nX   R                  5        HŽ  u  pg [        U[        5      (       a  [        Xr5      " S0 UD6XV'   M0  [        U[        5      (       a>  [        X&   [        5      (       a  [        XrU   5      " S0 UD6XV'   Mt  X&   " U40 UD6XV'   Mƒ  U" U40 UD6XV'   M�     U$ XB" U R                  40 UD60$ ! [
         a     Mµ  f = f)N© )Úitemsr3   rq   r7   ÚdictrK   r"   )r9   r!   r%   r+   r(   r€   r…   Úvs           r>   rs   rs     sÖ   € ö ØˆØ‘L×&Ñ&Ö(‰DˆAðÜ˜g¤s×+Ñ+Ü&-¨aÔ&9Ñ&C¸FÑ&C�L“OÜ ¬×.Ñ.Ü! '¡*¬c×2Ñ2Ü*1°!¸Q±ZÔ*@Ñ*JÀ6Ñ*J˜›à*1ª*°QÑ*A¸&Ñ*A˜›á&-¨aÑ&:°6Ñ&:�L“Oñ )ð Ðà˜g d§j¡jÑ;°FÑ;Ð<Ð<øô	 ó Úðús$   ¢(CÁACÂCÂCÃ
CÃCc
                ó$  ^^• [        T5      S:”  Gaü  / n
/ nUU4S jn[        U5      S:”  a‹  XU-      R                  X7U	S9R                  " U40 UD6nSnU R                  R                  SUS9 HC  u  nnUR                  nU" U5      nXß   UU'   U
R	                  U5        UR	                  U5        ME     GO3UTS S U-      R                  TS S XyS9R                  " U40 UD6R                  nSnU R                  SUS9 Hæ  u  nn[        T5      S:”  a	  U" U5      nOTnU
R	                  U5        Xß   R                  5       R                  n[        UR                  [        5      (       a4  [        R                  " U// UR                  R                  QS PS9Ul        O$[        U/UR                  R                  S9Ul        U
R	                  U5        UR	                  U5        Mè     U
(       d  U $ [        X®S9n[        U5      S:X  a  U$ OU nU R                  n[        T5      S:”  a´  UTU-      R                  TXyS9R                  " U40 UD6nUR                  5       n[         R"                  " [        T5      /[%        [        T5      5      5      nU Vs/ s H  nUR                  R                  U   PM     nnUR                  R'                  U5      Ul        O(UR)                  [*        R,                  UR                  S	9nUUU4$ s  snf )
Nr   c                ó0   >• U T4S[        T5      S-
  -  -   $ )Nrn   r-   ©rL   )rJ   rH   r(   s    €€r>   Ú_all_keyÚ,_generate_marginal_results.<locals>._all_key*  s    ø€ Ø˜Ð&¨´#°d³)¸a±-Ñ)@Ñ@Ð@r?   ©r)   r'   r-   )r   r)   rD   ©rj   rF   ©r"   )rL   rO   rP   r`   r6   Úto_framer3   r"   r   Úfrom_tuplesrE   r   rj   r   r#   ÚstackÚ	itertoolsÚchainrR   Úreorder_levelsÚ_constructor_slicedr[   Únan)r=   r9   r!   rG   rH   r%   r+   r)   r(   r'   Útable_piecesrƒ   r‘   ÚmarginÚcat_axisrJ   ÚpieceÚall_keyÚtransformed_piecer‚   r„   Únew_order_indicesrc   Únew_order_namess       `   `               r>   rw   rw     s  ù€ ô ˆ4ƒy�1„}àˆØˆö	Aô ˆt‹9�q‹=à˜F‘]Ñ#ß‘˜¸�Ð@ß‘ðàñ(à &ñ(ð ð
 ˆHà#Ÿg™gŸo™o°AÀ˜oÓI‘
��UØŸ™�Ù" 3›-�à!'¡��g‘à×#Ñ# EÔ*Ø×"Ñ" 7Ö+ó Jð �T˜"˜1�X Ñ&Ñ'ß‘˜˜b˜q˜¨H�ÐDß‘ðàñ(à &ñ(÷ ‘ð	 ð ˆHØ#Ÿm™m°!¸h˜mÓG‘
��UÜ�t“9˜q“=Ù& s›m‘Gà*�GØ×#Ñ# EÔ*Ø$*¡K×$8Ñ$8Ó$:×$<Ñ$<Ð!Ü˜eŸk™k¬:×6Ñ6ä.8×.DÒ.DØ ˜	Ø8 §¡× 1Ñ 1Ð8°4Ð8ñ/Ð%Õ+ô
 /4°W°IÀEÇKÁK×DTÑDTÑ.UÐ%Ô+ð ×#Ñ#Ð$5Ô6Ø×"Ñ" 7Ö+ñ% Hö( àˆLä˜LÑ8ˆFäˆt‹9˜‹>ØˆMð ð ˆØ—m‘mˆä
ˆ4ƒy�1ƒ}à�˜‘Ñß‰W�T HˆWÐ<ß‰Sðàñ$à"ñ$ð 	ð
  ×%Ñ%Ó'ˆ
ô &ŸOšO¬S°«Y¨K¼¼sÀ4»yÓ9IÓJÐÙ>OÓPÒ>O¸˜:×+Ñ+×1Ñ1°!Ô4Ñ>OˆÐPØ%×+Ñ+×:Ñ:¸?ÓKˆ
Õà×-Ñ-¬b¯f©f¸F¿N¹NÐ-ÐKˆ
à�; 
Ð*Ð*ùò Qs   Ê#Lc	                ó.  ^^• [        T5      S:”  aœ  / n	UU4S jn
[        U5      S:”  aC  UR                  X&US9U   R                  " U40 UD6nU
" 5       nX°U'   U nU	R                  U5        OOUR                  SXhS9R                  " U40 UD6nU
" 5       nX°U'   U nU	R                  U5        U$ U nU R                  n	[        T5      (       a%  UR                  TXhS9T   R                  " U40 UD6nO"[        [        R                  UR                  S9nXÙU4$ )Nr   c                 óP   >• [        T 5      S:X  a  T$ T4S[        T 5      S-
  -  -   $ )Nr-   rn   r�   )rH   r(   s   €€r>   r‘   Ú;_generate_marginal_results_without_values.<locals>._all_keyˆ  s.   ø€ Ü�4‹y˜A‹~Ø#Ð#Ø �? U¬c°$«i¸!©mÑ%<Ñ<Ð<r?   r“   )r   r)   r'   r•   )rL   rO   r}   r6   r#   r   r[   r�   )r=   r9   rG   rH   r%   r+   r)   r(   r'   rƒ   r‘   rŸ   r¢   r‚   r„   s      `   `       r>   ry   ry   x  s.  ù€ ô ˆ4ƒy�1ƒ}àˆö	=ô
 ˆt‹9�q‹=Ø—\‘\ $À&�\ÐIÈ$ÑO×UÒUØñØ!ñˆFñ “jˆGØ#�'‰NØˆFØ×Ñ˜wÕ'ð —\‘\¨°H�\ÐL×RÒRØñØ!ñˆFñ “jˆGØ#�'‰NØˆFØ×Ñ˜wÔ'ØˆMàˆØ—m‘mˆä
ˆ4‡y�yØ—\‘\ $°�\ÐIÈ$ÑO×UÒUØñ
Øñ
‰
ô œBŸF™F¨&¯.©.Ñ9ˆ
à 
Ð*Ð*r?   c                óÒ   • U c  / n U $ [        U 5      (       d?  [        U [        R                  [        [
        [        45      (       d  [        U 5      (       a  U /n U $ [        U 5      n U $ ©N)	r   r3   r[   Úndarrayr   r   r   Úcallabler4   )Úbys    r>   r2   r2   ­  s_   € Ø	�zØˆð €Iô 	�"�‰Ü�bœ2Ÿ:™:¤u¬i¼ÐA×BÑBÜ�B�<‰<àˆTˆð €Iô �"‹XˆØ€Ir?   )r"   r!   c               óè  • [         R                  " U5      n[        S U R                  R                   5       5      (       aW  U R                  SS9n U R                  R                   Vs/ s H  oUb  UO[        R                  PM     snU R                  l        U[        R                  L aR  U[        R                  La  [         R                  " U5      nO/ nU[        R                  L nU R                  Xd-   US9nGOvU[        R                  L a—  [        U R                  [        5      (       aH  [        U R                  R                  5       V	s/ s H  o�R                  R                  U	5      PM     n
n	OXU R                  U R                  U R                  R                  S9/n
O([         R                  " U5       Vs/ s H  o°U   PM	     n
nU Vs/ s H  oÀU   PM	     nnU
R!                  U5        [        R"                  " U
5      n[%        U5      (       a=  [        U[&        5      (       d(  U R)                  X   R*                  U[-        SU5      S9nOU R                  X   R*                  US	9n[-        S
UR/                  U5      5      nUR                  R                   Vs/ s H  oU[        R                  La  UOSPM     snUR                  l        U$ s  snf s  sn	f s  snf s  snf s  snf )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  ó(   #   • U  H  oS L v •  M
     g 7frª   rŠ   )Ú.0rj   s     r>   Ú	<genexpr>Úpivot.<locals>.<genexpr>Z  s   é € Ð
5Ò$4˜D�4�<Ò$4ùs   ‚F)ÚdeepN)r6   r”   r   )r"   r#   r•   r   )ÚcomÚconvert_to_list_likeÚanyr"   rE   Úcopyr   Ú
no_defaultÚ	set_indexr3   r   rR   rQ   rr   rœ   rj   ÚextendÚfrom_arraysr
   rx   rv   Ú_valuesr   rS   )r9   r#   r"   r!   Úcolumns_listlikerj   rH   r6   Úindexedrc   Ú
index_listÚidxÚcolÚdata_columnsÚ
multiindexr‚   s                   r>   ÚpivotrÄ   »  sŠ  € ôt ×/Ò/°Ó8Ðô
 Ñ
5 D§J¡J×$4Ò$4Ó
5×5Ñ5Ø�y‰y˜eˆyÐ$ˆàEIÇZÁZ×EUÒEUó
ÚEU¸TÑ$‰D¬#¯.©.Ò8ÑEUñ
ˆ�
‰
Ôð
 ”—‘ÒØœŸ™Ò&Ü×+Ò+¨EÓ2‰DàˆDàœ#Ÿ.™.Ð(ˆð —.‘.ØÑ#Øð !ð 
Šð ”C—N‘NÒ"Ü˜$Ÿ*™*¤j×1Ñ1ô =BÀ$Ç*Á*×BTÑBTÔ<UóÚ<U°q—J‘J×/Ñ/°Ö2Ñ<Uð ð �
ð
 ×,Ñ,¨T¯Z©Z¸d¿j¹j¿o¹oÐ,ÐNð‘
ô 03×/GÒ/GÈÔ/NÓOÒ/N¨˜sœ)Ñ/NˆJÐOá-=Ó>Ò-= c˜Sœ	Ñ-=ˆÐ>Ø×Ñ˜,Ô'Ü×+Ò+¨JÓ7ˆ
ä˜×Ñ¬
°6¼5×(AÑ(Aà×'Ñ'Ø‘×$Ñ$Ø ÜÐ-¨vÓ6ð (ð ‰Gð ×.Ñ.¨t©|×/CÑ/CÈ:Ð.ÐVˆGô
 �+˜wŸ™Ð/?Ó@ÓA€FàAGÇÁ×ASÒASóÚAS¸œCŸN™NÒ*‰°Ò4ÑASñ€F‡L�LÔð €Mùòo
ùò.ùò Pùâ>ùò$s   Á)KÅ$K Ç K%ÇK*Ê' K/c
           
     ó¨  • Uc  Ub  [        S5      eUb  Uc  [        S5      e[        U 5      (       d  U /n [        U5      (       d  U/nSn
X-    Vs/ s H"  n[        U[        [        45      (       d  M   UPM$     nnU(       a  [        USSS9n
[        XSS9n[        XS	S9n[        X45      u  nnnnS
SKJ	n  0 [        [        XàSS95      E[        [        UUSS95      EnU" UU
S9nUc  S
US'   [        S
S.nO	UUS'   SU0nUR                  "  SUUUUUUS.UD6nU	SLa  [        UX–US9nUR                  US
S9nUR                  USS9nU$ s  snf )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   r   )Ústrictr•   Ú	__dummy__)r%   r$   r%   )r"   r#   r&   r(   r'   r)   )Ú	normalizer&   r(   )r"   r/   r-   )r#   r/   )rÊ   )rN   r   r3   r   r   r   Ú
_get_namesÚ_build_names_mapperr   r   rŒ   ÚziprL   r0   Ú
_normalizeÚrename_axis)r"   r#   r!   ÚrownamesÚcolnamesr%   r&   r(   r'   rË   Ú
common_idxre   Ú	pass_objsÚrownames_mapperÚunique_rownamesÚcolnames_mapperÚunique_colnamesr   r9   Údfr+   r=   s                         r>   ÚcrosstabrÚ   –  s¸  € ðh �~˜'Ñ-ÜÐAÓBÐBàÑ˜g™oÜÐDÓEÐEä˜u×%Ñ%Ø�ˆÜ˜w×'Ñ'Ø�)ˆà€JØ!šOÓXšO�q¬z¸!¼iÌÐ=V×/W—™O€IÐXÞÜ+¨IÀÈEÑRˆ
ä˜%°%Ñ8€HÜ˜'°EÑ:€Hô 	˜HÓ/ñØØØØõ !ðÜ
Œs�?°$Ñ7Ó
8ðä
Œs�? G°DÑ9Ó
:ð€Dñ 
�4˜zÑ	*€Bà�~Øˆˆ;‰Ü °Ñ2‰à ˆˆ;‰Ø˜WÐ%ˆð �NŠNØð	àØØØ!ØØñ	ð ñ	€Eð ˜ÒÜØ˜YÀlñ
ˆð ×Ñ O¸!ÐÐ<€EØ×Ñ o¸AÐÐ>€Eà€Lùòi Ys   ÁEÁ4Ec                ó~  • [        U[        [        45      (       d
  SSS.n XA   nUSL a1  S S S S	.nUS
   US'    Xa   nU" U 5      n U R                  S5      n U $ USL Ga–  U R                  nU R                  n	U R                  SS S 24   R                  n
X:;  X::g  -  (       a  [	        U S35      eU R                  S S2S4   nU R                  SS S24   nU R                  S S2S S24   n [        XSS9n US:X  a6  X»R                  5       -  n[        X/SS9n U R                  S5      n X�l        U $ US:X  a;  XÌR                  5       -  nU R                  USS9n U R                  S5      n X€l        U $ US
:X  d  USL am  X»R                  5       -  nXÌR                  5       -  nSUR                  U'   [        X/SS9n U R                  USS9n U R                  S5      n X€l        X�l        U $ [	        S5      e[	        S5      e! [         a  n[	        S5      UeS nAff = f! [         a  n[	        S5      UeS nAff = f)Nr"   r#   )r   r-   zNot a valid normalize argumentFc                ó>   • X R                  SS9R                  SS9-  $ ©Nr-   rF   r   ©Úsum©re   s    r>   Ú<lambda>Ú_normalize.<locals>.<lambda>z  s   € ˜Q§¡¨A  ×!2Ñ!2¸Ð!2Ð!:Ò:r?   c                ó&   • X R                  5       -  $ rª   rÞ   rà   s    r>   rá   râ   {  s   €  §U¡U£W¢r?   c                ó<   • U R                  U R                  SS9SS9$ rÝ   )Údivrß   rà   s    r>   rá   râ   |  s   € ˜qŸu™u Q§U¡U° U ]¸˜uÑ;r?   )rA   r#   r"   rA   Tr   éÿÿÿÿz not in pivoted DataFrame)rË   r&   r-   rF   )Úignore_indexzNot a valid margins argument)r3   Úboolrq   rI   rN   rX   r"   r#   Úilocrj   rÏ   rß   r   ru   Úloc)r=   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 €Lðc 
�D‹à—k‘kˆØŸ™ˆØŸ*™* Rª UÑ+×0Ñ0ˆð Ñ/°LÑ4S×TÜ ˜~Ð-FÐGÓHÐHØŸ
™
 3 B 3¨ 7Ñ+ˆØ—z‘z " c r c 'Ñ*ˆð —
‘
˜3˜B˜3   ˜8Ñ$ˆô ˜5¸uÑEˆð ˜	Ó!Ø)×,=Ñ,=Ó,?Ñ?ˆMÜ˜EÐ1¸Ñ:ˆEØ—L‘L “OˆEØ)ŒMð2 €Lð/ ˜'Ó!Ø'×*:Ñ*:Ó*<Ñ<ˆLØ×*Ñ*¨<ÀdÐ*ÐKˆEØ—L‘L “OˆEØ%ŒKð& €Lð# ˜%Ó 9°Ò#4Ø)×,=Ñ,=Ó,?Ñ?ˆMØ'×*:Ñ*:Ó*<Ñ<ˆLØ-.ˆL×Ñ˜\Ñ*Ü˜EÐ1¸Ñ:ˆEØ×*Ñ*¨<ÀdÐ*ÐKˆEà—L‘L “OˆEØ%ŒKØ)ŒMð €Lô Ð=Ó>Ð>ô Ð7Ó8Ð8øôI ó 	HÜÐ=Ó>ÀCÐGûð	Hûô ó 	HÜÐ=Ó>ÀCÐGûð	Hús.   ¢H ½H! È
HÈHÈHÈ!
H<È+H7È7H<c                ól  • Ucm  / n[        U 5       HZ  u  p4[        U[        5      (       a*  UR                  b  UR	                  UR                  5        MD  UR	                  U SU 35        M\     U$ [        U5      [        U 5      :w  a  [        S5      e[        U[        5      (       d  [        U5      nU$ )NÚ_z*arrays and names must have the same length)Ú	enumerater3   r   rj   r6   rL   ÚAssertionErrorr4   )ÚarrsrE   rÈ   rc   Úarrs        r>   rÌ   rÌ   ½  s˜   € Ø�}ØˆÜ –o‰FˆAÜ˜#œy×)Ñ)¨c¯h©hÑ.BØ—‘˜SŸX™XÖ&à—‘ ˜x q¨¨˜_Ö-ñ	 &ð €Lô ˆu‹:œ˜T›Ó"Ü Ð!MÓNÐNÜ˜%¤×&Ñ&Ü˜“KˆEà€Lr?   c                ó´  • [        U 5      [        U5      -  n[        U 5       VVs0 s H  u  p4XB;   d  M  SU 3U_M     nnn[        U 5       VVs/ s H  u  p4XB;   a  SU 3OUPM     nnn[        U5       VVs0 s H  u  p4XB;   d  M  SU 3U_M     nnn[        U5       VVs/ s H  u  p4XB;   a  SU 3OUPM     nnnXVXx4$ s  snnf s  snnf s  snnf s  snnf )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_)rz   rö   )	rÑ   rÒ   Ú	dup_namesrc   rj   rÕ   rÖ   r×   rØ   s	            r>   rÍ   rÍ   Î  s  € ô: �H“¤ H£Ñ-€Iô )2°(Ô(;ôÚ(;™W˜Q¸tÑ?PÓˆ$ˆqˆcˆ
�DÒÑ(;ð ñ ô BKÈ8ÔATôÚAT±g°a�dÓ'ˆ$ˆqˆc‰
¨TÒ1ÑATð ñ ô
 )2°(Ô(;ôÚ(;™W˜Q¸tÑ?PÓˆ$ˆqˆcˆ
�DÒÑ(;ð ñ ô BKÈ8ÔATôÚAT±g°a�dÓ'ˆ$ˆqˆc‰
¨TÒ1ÑATð ñ ð ¨_ÐMÐMùóùóùóùós"   ¦Cµ
CÁCÁ9CÂ
CÂ#C)
NNNÚmeanNFTÚAllTT)r9   r   r%   r   r&   rè   r'   rè   r(   r   r)   rè   r*   rè   Úreturnr   )r9   r   r%   z!AggFuncTypeBase | AggFuncTypeDictr&   rè   r'   rè   r(   r   r)   rè   r*   rè   r   r   )rÿ   NT)
r=   zDataFrame | Seriesr9   r   r)   rè   r(   r   r'   rè   )rÿ   )r9   r   r(   r   )rÿ   T)r9   r   r)   rè   r(   r   r'   rè   )
r=   r   r9   r   r)   rè   r(   r   r'   rè   )
r9   r   r#   r   r"   úIndexLabel | lib.NoDefaultr!   r  r   r   )NNNNFrÿ   TF)
r&   rè   r(   r   r'   rè   rË   z/bool | Literal[0, 1, 'all', 'index', 'columns']r   r   )r=   r   r&   rè   r(   r   r   r   )rÇ   )rÈ   rq   r   r4   )rÑ   ú	list[str]rÒ   r  r   z;tuple[dict[str, str], list[str], dict[str, str], list[str]])>Ú
__future__r   r™   Útypingr   r   r   Únumpyr[   Ú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   r0   r5   r^   rs   rw   ry   r2   r¸   rÄ   rÚ   rÏ   rÌ   rÍ   rŠ   r?   r>   Ú<module>r     s\  ðÝ "ã ÷ñ ó å Ý .å ;÷ñ õ
 5÷÷
 !Ð  Ý '÷ñ õ
 .Ý %æ÷÷
õ õ !ñ ˆHÓð Ø
ØØ!ØØØØ"ØØðb:Ø
ðb:ð
 ðb:ð ðb:ð ðb:ð ðb:ð ðb:ð ðb:ð ôb:ó ðb:ðJ@Ø
ð@ð
 /ð@ð ð@ð ð@ð ð@ð ð@ð ð@ð ô@ðX #ØØð_Øð_à
ð_ð ð_ð ð_ð õ_ðF HMð=Ø
ð=Ø<Dõ=ð@ #Øð]+à
ð]+ð ð]+ð ð]+ð õ]+ðP #Øð2+Øð2+à
ð2+ð ð2+ð ð2+ð õ2+òjñ ˆHÓð
 ),¯©Ø),¯©ñWØ
ðWð ðWð &ð	Wð
 'ðWð ôWó ðWñt ˆHÓð ØØØØØ"ØØAFðSð ðSð ðSð ðSð ?ðSð ôSó ðSðn JOðMØðMØ*.ðMØ>FðMàõMö`ð"-NØð-NØ#,ð-Nà@õ-Nr?   