-
-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pivot_table drop rows whose entries are all NaN #21969
Labels
Bug
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Comments
gfyoung
added
the
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
label
Jul 18, 2018
@noob-saibot : Can you add a reference to the old issue? cc @jreback : Is it intended to drop |
I'm also experiencing this issue in 0.23.4 with an additional snag. If you set dropna=False it will add nonexistent rows to the output table. import pandas as pd
from numpy import nan
data_set = [
{'x': 0, 'y': 0, 'parameter_id': 'a', 'result_value': 3.0},
{'x': 0, 'y': 0, 'parameter_id': 'b', 'result_value': 1.0},
{'x': 0, 'y': 0, 'parameter_id': 'c', 'result_value': 3.0},
{'x': 0, 'y': 0, 'parameter_id': 'd', 'result_value': nan},
{'x': 0, 'y': 1, 'parameter_id': 'a', 'result_value': 1.0},
{'x': 0, 'y': 1, 'parameter_id': 'b', 'result_value': 3.0},
{'x': 0, 'y': 1, 'parameter_id': 'c', 'result_value': nan},
{'x': 0, 'y': 1, 'parameter_id': 'd', 'result_value': nan},
{'x': 0, 'y': 2, 'parameter_id': 'a', 'result_value': 1.0},
{'x': 0, 'y': 2, 'parameter_id': 'b', 'result_value': 3.0},
{'x': 0, 'y': 2, 'parameter_id': 'c', 'result_value': nan},
{'x': 0, 'y': 2, 'parameter_id': 'd', 'result_value': nan},
{'x': 1, 'y': 0, 'parameter_id': 'a', 'result_value': 1.0},
{'x': 1, 'y': 0, 'parameter_id': 'b', 'result_value': 3.0},
{'x': 1, 'y': 0, 'parameter_id': 'c', 'result_value': nan},
{'x': 1, 'y': 0, 'parameter_id': 'd', 'result_value': nan},
{'x': 1, 'y': 1, 'parameter_id': 'a', 'result_value': nan},
{'x': 1, 'y': 1, 'parameter_id': 'b', 'result_value': nan},
{'x': 1, 'y': 1, 'parameter_id': 'c', 'result_value': nan},
{'x': 1, 'y': 1, 'parameter_id': 'd', 'result_value': nan}]
df = pd.DataFrame(data_set)
df.pivot_table(index=['x', 'y'], columns='parameter_id',
values='result_value', dropna=False).reset_index()
Output
Expected Output
|
12 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug
Missing-data
np.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Reshaping
Concat, Merge/Join, Stack/Unstack, Explode
Pivot_table is silently dropping row whose entries fully consisting with NaN. (according to the documentation - dropna : boolean, default True; Do not include columns whose entries are all NaN)
It works fine at version 0.21.1 and 0.22.0.
I found only old bug from 2013.
Expected Output
Output of
pd.show_versions()
pandas: 0.23.1
pytest: None
pip: 9.0.1
setuptools: 28.8.0
Cython: 0.27
numpy: 1.14.5
scipy: None
pyarrow: 0.9.0
xarray: None
IPython: 6.2.1
sphinx: None
patsy: 0.4.1
dateutil: 2.7.3
pytz: 2018.4
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: 0.4.0
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: