keepdims fails when taking mean
See original GitHub issueCode Sample, a copy-pastable example if possible
import pandas as pd
import numpy as np
print(np.mean(np.zeros((30, 30)), axis=0, keepdims=True).shape,
pd.DataFrame(np.zeros((30, 30))).mean( axis=0, keepdims=True).shape,
np.mean(pd.DataFrame(np.zeros((30, 30))), axis=0, keepdims=True).shape)
Problem description
The keepdims
argument is ignored when taking the mean of pandas dataframes, resulting in an array of lower dimensionality.
Oddly, there’s no documentation for pd.DataFrame.mean suggesting keepdims should even be allowed as an argument, but it accepts it with no effect. This also modifies the behavior of np.mean.
Expected Output
(1, 30) (1,30,) (1,30,)
Output of pd.show_versions()
(1, 30) (30,) (30,)
pandas: 0.17.1 nose: 1.3.7 pip: None setuptools: None Cython: None numpy: 1.11.0 scipy: 0.17.0 statsmodels: None IPython: 2.4.1 sphinx: None patsy: None dateutil: 2.4.2 pytz: 2014.10 blosc: None bottleneck: None tables: 3.2.2 numexpr: 2.4.3 matplotlib: 1.5.1 openpyxl: None xlrd: None xlwt: None xlsxwriter: None lxml: None bs4: 4.4.1 html5lib: 0.999 httplib2: None apiclient: None sqlalchemy: None pymysql: None psycopg2: None Jinja2: None
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
Ok, let’s close for now. We can close for now. We can revisit a
keepdims
keyword in the future if there’s interest.Ah, that makes sense. Nope, looking at the code it only checks that there’s a
mean
property, not even if it’s a method:Well, definitely not a pandas bug. Thanks for looking at that.