A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/48681 below:

Int64` when using `pd.pivot_table(..., margins=True)` with Int64 values · Issue #48681 · pandas-dev/pandas · GitHub

Pandas version checks Reproducible Example
import pandas as pd
import numpy as np


df = pd.DataFrame(
    {
        "state": ["CA", "WA", "CO", "AZ"] * 3,
        "office_id": list(range(1, 7)) * 2,
        "sales": [np.random.randint(100_000, 999_999) for _ in range(12)]
    }
).astype(
    {
        "sales": pd.Int64Dtype()
    }
)

df.pivot_table(index="office_id", columns="state", margins=True, aggfunc="sum")
Issue Description

This issue looks similar to this one, however I have confirmed the issue is still present on 1.5.0. The difference here is the addition of margins=True.

Expected Behavior
import pandas as pd
import numpy as np


df = pd.DataFrame(
    {
        "state": ["CA", "WA", "CO", "AZ"] * 3,
        "office_id": list(range(1, 7)) * 2,
        "sales": [np.random.randint(100_000, 999_999) for _ in range(12)]
    }
).astype(
    {
        "sales": np.int64  # works
    }
)

df.pivot_table(index="office_id", columns="state", margins=True, aggfunc="sum")
Installed Versions INSTALLED VERSIONS

commit : 87cfe4e
python : 3.10.4.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 165 Stepping 3, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : English_United Kingdom.1252

pandas : 1.5.0
numpy : 1.23.1
pytz : 2022.1
dateutil : 2.8.2
setuptools : 63.4.1
pip : 22.1.2
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.3
IPython : 8.4.0
pandas_datareader: None
bs4 : 4.11.1
bottleneck : None
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.5.2
numba : None
numexpr : None
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.9.1
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4