• [X] I have checked that this issue has not already been reported.
  • [X] I have confirmed this bug exists on the latest version of pandas.
  • [ ] (optional) I have confirmed this bug exists on the master branch of pandas.

Code Sample, a copy-pastable example

From StackOverflow question posted by Usal

df=pd.DataFrame({'Col1':[1, '-','-'], 'Col2':['-','-',2]})
df.sum(axis=1)
# 0    0.0
# 1    0.0
# 2    0.0
# dtype: float64

df.sum(axis=0)
# Series([], dtype: float64)

Problem description

Inconsistent output when same operation i.e. df.sum is applied over axis 0 and 1.

Expected Output

df.sum(axis=0)
# Col1 0.0
# Col2 0.0
# dtype: float64

df.sum(axis=1)
# 0 0.0
# 1 0.0
# 2 0.0
# dtype: float64

Output of pd.show_versions()


INSTALLED VERSIONS
------------------
commit           : 7d32926db8f7541c356066dcadabf854487738de
python           : 3.8.5.final.0
python-bits      : 64
OS               : Linux
OS-release       : 5.8.0-43-generic
Version          : #49~20.04.1-Ubuntu SMP Fri Feb 5 09:57:56 UTC 2021
machine          : x86_64
processor        : x86_64
byteorder        : little
LC_ALL           : None
LANG             : en_IN
LOCALE           : en_IN.ISO8859-1

pandas           : 1.2.2
numpy            : 1.19.5
pytz             : 2019.3
dateutil         : 2.7.3
pip              : 20.0.2
setuptools       : 45.2.0
Cython           : None
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : None
lxml.etree       : None
html5lib         : 1.0.1
pymysql          : None
psycopg2         : None
jinja2           : 2.10.1
IPython          : 7.13.0
pandas_datareader: None
bs4              : None
bottleneck       : None
fsspec           : None
fastparquet      : None
gcsfs            : None
matplotlib       : 3.1.2
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyxlsb           : None
s3fs             : None
scipy            : None
sqlalchemy       : None
tables           : None
tabulate         : None
xarray           : None
xlrd             : None
xlwt             : None
numba            : None

Comment From: attack68

I changed the example for consistency, and confirm the result. No idea about cause or solution.

df=pd.DataFrame({'Col1':[1,'-'], 'Col2':['-',2]}, index=['Row1', 'Row2'])
print(df.sum(axis=1))
print(df.sum(axis=0))

Row1    0.0
Row2    0.0
dtype: float64
Series([], dtype: float64)

Comment From: jbrockmendel

With nuisance columns no longer silently dropped, these both now correctly raise. Closing.