Closed
Description
Code Sample, a copy-pastable example if possible
df = pd.DataFrame(
[[123, "a", 1.0], [123, "b", 2.0]],
columns=["id", "category", "value"]
)
df = df.set_index(["id", "category"])
df[df.value < 0].groupby("id").sum()
Problem description
When groupby is over a Int64Index
in a MultiIndex
for an empty DataFrame, the groupby fails with error: ValueError: Unable to fill values because Int64Index cannot contain NA
Expected Output
The groupby should not raise an error, instead the code above should output an empty DataFrame as would happen for df[df.value < 0].groupby("category").sum()
Output of pd.show_versions()
INSTALLED VERSIONS
------------------
commit : None
python : 3.6.9.final.0
python-bits : 64
OS : Darwin
OS-release : 18.7.0
machine : x86_64
processor : i386
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8
pandas : 1.0.0
numpy : 1.18.1
pytz : 2019.2
dateutil : 2.8.0
pip : 18.1
setuptools : 41.6.0
Cython : None
pytest : 5.1.2
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : 2.8.3 (dt dec pq3 ext lo64)
jinja2 : 2.10.1
IPython : 7.8.0
pandas_datareader: None
bs4 : 4.8.0
bottleneck : None
fastparquet : None
gcsfs : None
lxml.etree : None
matplotlib : 3.1.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 0.13.0
pytables : None
pytest : 5.1.2
pyxlsb : None
s3fs : None
scipy : 1.4.1
sqlalchemy : 1.3.6
tables : None
tabulate : 0.8.6
xarray : None
xlrd : 1.2.0
xlwt : None
xlsxwriter : None
numba : None