Description
Code Sample, a copy-pastable example if possible
import pandas as pd
df = pd.DataFrame({
'A': [0, 1, 2], 'B': ['a', 'b', 'c'], 'C': [4, 5, 6]
})
df.mean(axis=0, numeric_only=False, skipna=False)
Problem description
Instead of outputting a NaN
for a non-numeric column of strings when trying to take the mean, it instead throws TypeError: could not convert string 'abc' to float
.
Expected Output
I would expect this to output a series with values [1, NaN, 5]
.
My work-around is currently df.apply(pd.to_numeric, args=['coerce']).mean(axis=0, skipna=False)
, which outputs the expected result.
Output of pd.show_versions()
pandas: 0.24.2
pytest: None
pip: 19.1.1
setuptools: 40.6.3
Cython: 0.29.2
numpy: 1.16.0
scipy: 1.2.1
pyarrow: 0.12.0
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.7.5
pytz: 2018.9
blosc: None
bottleneck: None
tables: 3.4.4
numexpr: 2.6.9
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: 1.2.16
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None